View Single Post
  #4   Report Post  
Posted to microsoft.public.word.pagelayout
DRob DRob is offline
external usenet poster
 
Posts: 3
Default Content control prompt



"DRob" wrote:

That's brilliant, I never thought to approach it from the printing side of
the equation. I'm a bit of a novice with VBA, what do I need to do to have
the macros run whenever the files or templates with content controls are
used, do I have to activate the macro or can this be done automatically.?

"Jay Freedman" wrote:

On Sat, 3 May 2008 06:48:00 -0700, DRob wrote:

Is there a way to prevent the content control prompt (eg:"click here to enter
info") from printing when no info is entered? In the old legacy text box a
gray box would show but if no text was entered in would not show up in the
document


There doesn't appear to be anything built in for this, but there are at least
two different things you can do with a macro.

The general idea is that you intercept the print command and either set the
Hidden font attribute of the controls to true (if you want the controls to
collapse) or change the font color to white (if you want to maintain the
spacing), do the printing, and then undo the font changes.

Since there are two printing commands, one for the menu item that shows the
Print dialog and one for the toolbar button that prints immediately, you need
two macros. Here are a pair that hide the controls that have no entries. If you
want to maintain the spacing, replace "Hidden = True" with "Color =
wdColorWhite" and replace Hidden = False" with "Color = wdColorAutomatic".

Sub FilePrint()
Dim myCC As ContentControl

With ActiveDocument
' hide the controls that have default text
For Each myCC In .ContentControls
If myCC.ShowingPlaceholderText Then
myCC.Range.Font.Hidden = True
End If
Next

' print
Dialogs(wdDialogFilePrint).Show

' reverse the hiding
For Each myCC In .ContentControls
If myCC.ShowingPlaceholderText Then
myCC.Range.Font.Hidden = False
End If
Next
End With
End Sub

Sub FilePrintDefault()
Dim myCC As ContentControl

With ActiveDocument
' hide the controls that have default text
For Each myCC In .ContentControls
If myCC.ShowingPlaceholderText Then
myCC.Range.Font.Hidden = True
End If
Next

' print
ActiveDocument.PrintOut Background:=False

' reverse the hiding
For Each myCC In .ContentControls
If myCC.ShowingPlaceholderText Then
myCC.Range.Font.Hidden = False
End If
Next
End With
End Sub

See http://www.gmayor.com/installing_macro.htm if needed.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.