Before Print

The BeforePrint event handler enables you to take action in the document before printing it. For example, you might want to hide a graphic in the document if you plan to use preprinted letterhead. The code in Listing 6.37 sets the style of the graphic to hidden, displays the print dialog so that the user can print the document, and then sets the Hidden property of the style to False. Finally, it sets the Cancel property to True so that the document is not printed again. This code example assumes that the document contains a graphic with a style named Graphic applied.

Listing 6.37. Hiding a graphic before sending a document to print

Private Sub ThisDocument_BeforePrint(ByVal sender As Object, _ ByVal e As System.ComponentModel.CancelEventArgs) _ Handles Me.BeforePrint

Me.Styles("Graphic").Font.Hidden = True

Application.Dialogs(Word.WdWordDialog.wdDialogFilePrint) _ .Show()

Me.Styles("Graphic").Font.Hidden = False e.Cancel = True

End Sub

0 0

Post a comment