MACROBUTTON fields do not appear in print out when no text is inse

J

Jo Gjessing

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
 
J

Jay Freedman

Jo said:
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.
 
J

Jo Gjessing

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 said:
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.
 
G

Graham Mayor

Change the line
fld.Result.Font.Color = wdColorWhite
to
fld.Code.Font.Color = wdColorWhite

and
fld.Result.Font.Color = wdColorAutomatic
to
fld.Code.Font.Color = wdColorAutomatic

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Jo said:
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 said:
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.
 
J

Jay Freedman

Hi Jo,

You're correct; that kind of code works for all (or almost all) other kinds
of fields, but for reasons I don't understand, the MacroButton field is
immune to and changes of .Result.Font. There are probably other ways to
accomplish it, but the following modification works (yes, I tested this
one).

Sub FilePrint()
Dim selRange As Range
Dim fld As Field

' save starting location
Set selRange = Selection.Range

Application.ScreenUpdating = False
' turn all MacroButton fields white
For Each fld In ActiveDocument.Fields
If fld.Type = wdFieldMacroButton Then
fld.Select
Selection.Font.Color = wdColorWhite
End If
Next
' restore original selection
selRange.Select
Application.ScreenUpdating = True

' print
On Error Resume Next
Dialogs(wdDialogFilePrint).Show

Application.ScreenUpdating = False
' restore MacroButton fields
For Each fld In ActiveDocument.Fields
If fld.Type = wdFieldMacroButton Then
fld.Select
Selection.Font.Color = wdColorAutomatic
End If
Next
selRange.Select
Application.ScreenUpdating = True
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.


Jo said:
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 said:
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.
 
J

Jay Freedman

I should have read Graham's reply before I hit Send. <g>

Jay said:
Hi Jo,

You're correct; that kind of code works for all (or almost all) other
kinds of fields, but for reasons I don't understand, the MacroButton
field is immune to and changes of .Result.Font. There are probably
other ways to accomplish it, but the following modification works
(yes, I tested this one).

Sub FilePrint()
Dim selRange As Range
Dim fld As Field

' save starting location
Set selRange = Selection.Range

Application.ScreenUpdating = False
' turn all MacroButton fields white
For Each fld In ActiveDocument.Fields
If fld.Type = wdFieldMacroButton Then
fld.Select
Selection.Font.Color = wdColorWhite
End If
Next
' restore original selection
selRange.Select
Application.ScreenUpdating = True

' print
On Error Resume Next
Dialogs(wdDialogFilePrint).Show

Application.ScreenUpdating = False
' restore MacroButton fields
For Each fld In ActiveDocument.Fields
If fld.Type = wdFieldMacroButton Then
fld.Select
Selection.Font.Color = wdColorAutomatic
End If
Next
selRange.Select
Application.ScreenUpdating = True
End Sub


Jo said:
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.
 
G

Graham Mayor

I do that all the time :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Jay said:
I should have read Graham's reply before I hit Send. <g>

Jay said:
Hi Jo,

You're correct; that kind of code works for all (or almost all) other
kinds of fields, but for reasons I don't understand, the MacroButton
field is immune to and changes of .Result.Font. There are probably
other ways to accomplish it, but the following modification works
(yes, I tested this one).

Sub FilePrint()
Dim selRange As Range
Dim fld As Field

' save starting location
Set selRange = Selection.Range

Application.ScreenUpdating = False
' turn all MacroButton fields white
For Each fld In ActiveDocument.Fields
If fld.Type = wdFieldMacroButton Then
fld.Select
Selection.Font.Color = wdColorWhite
End If
Next
' restore original selection
selRange.Select
Application.ScreenUpdating = True

' print
On Error Resume Next
Dialogs(wdDialogFilePrint).Show

Application.ScreenUpdating = False
' restore MacroButton fields
For Each fld In ActiveDocument.Fields
If fld.Type = wdFieldMacroButton Then
fld.Select
Selection.Font.Color = wdColorAutomatic
End If
Next
selRange.Select
Application.ScreenUpdating = True
End Sub


Jo said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top