Graham Mayor

... helping to ease the lives of Microsoft Word users.


Many people access the material from this web site daily. Most just take what they want and run. That's OK, provided they are not selling on the material as their own; however if your productivity gains from the material you have used, a donation from the money you have saved would help to ensure the continued availability of this resource. Click the appropriate button above to access PayPal.

Create a non-printing print button in a form document

The purpose of this page is to explain how to print a protected form that contains an ActiveX print button without the button appearing in the print.

This process requires the use of a macros. You cannot force users to run macros, but presumably you thought of that when deciding to use a Print button, rather than allow users to simply print from Word.

In the above illustration there is an ActiveX button inserted from the ActiveX legacy controls on the Developer tab of the ribbon.

Create a new character style, based simply on the underlying paragraph and call it 'Hidden'. The name is not that important, but it handily reflects the function it will be put to. We are only interested in having the name available to apply to the button, so the next step is to apply the style to the button.

As the style is exactly the same as the underlying style, at this point, nothing will appear to change. This is the default condition.

With Design Mode selected from the Developer Tab, right click the button and select 'View Code'. Copy and paste the following code to the vba editor:

 
Option Explicit

Private Sub CommandButton1_Click()
With ActiveWindow.View
.ShowHiddenText = False
.ShowAll = False
End With
Options.PrintHiddenText = False
With ActiveDocument
.Styles("Hidden").Font.Hidden = True
.PrintOut Copies:=1
.Styles("Hidden").Font.Hidden = False
End With
End Sub

Close the VBA editor. Protect and Save the form as a macro enabled document or template.

The form is now ready for completion (or in the case of a template for new documents to be created from it).

Fill in the data and click the button. The 'Hidden' style will be formatted as hidden. The document will be sent to the printer, and the style will be returned to its default state.  Nothing will appear to happen to the form itself. The form will remain protected, but the printout will not display the button.

 

 

 Print Form Button

This page was inspired by a question I responded to in the MSDN VBA forum. It provides a way of printing a form via a Print button in the form, but without the button appearing in the print-out.