Hi Jay.
Thank you very much for your rapid answer. To me your code seems to
be very reasonable. When I start a macro with your code, however,
both fields and text which have replaced fields are printed. To see
if the change of color works, I've also made a makro with just this
part of your code:
' turn all MacroButton fields white
For Each fld In ActiveDocument.Fields
If fld.Type = wdFieldMacroButton Then
fld.Result.Font.Color = wdColorWhite
End If
Next
When running this macro no change of color to white appeared.
Can you please look through it again and give me a few words. I
forgot to tell that I use Word 2003, don't know if this is
important. Thank you very much.
Jo
Jay Freedman skrev:
Jo Gjessing wrote:
Hi all,
In a Word document of mine I have a few MACROBUTTON fields which
look like this: {MACROBUTTON NoMacro [Click here and write a
text]}. When the document is printed and no text string is
inserted into the field I want the field to be blank in the print
out. When a text string is inserted into the field and it is
printed I want the string to appear in the print out. Do you know
how I do this? If you have any idea please let me know.
Thank you very much in advance.
Jo
First, recognize that when you click on a MacroButton field and
type something, the "Typing replaces selection" behavior deletes
the field and leaves only the newly typed regular text. That means
the only MacroButton fields remaining in the document are ones
that have not been typed over.
The general idea is to write a macro that intercepts the print
command
(
http://www.word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm),
changes the remaining MacroButton fields' font to white, does the
printing, and then restores the font color:
Sub FilePrint()
Dim fld As Field
' turn all MacroButton fields white
For Each fld In ActiveDocument.Fields
If fld.Type = wdFieldMacroButton Then
fld.Result.Font.Color = wdColorWhite
End If
Next
' print
On Error Resume Next
Dialogs(wdDialogFilePrint).Show
' restore MacroButton fields
For Each fld In ActiveDocument.Fields
If fld.Type = wdFieldMacroButton Then
fld.Result.Font.Color = wdColorAutomatic
End If
Next
End Sub
You'll also want a second macro named FilePrintDefault, which
intercepts the "immediate print" button on the toolbar. The code
inside is the same except that the line
Dialogs(wdDialogFilePrint).Show is replaced by
ActiveDocument.PrintOut Background:=False
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.