Export (0) Print
Expand All

Application.BeforePrint Event

Office 2007
Occurs before the publication is printed or previewed. .

Version Information
 Version Added:  Publisher 2007


expression.BeforePrint(Doc, Cancel)

expression   An expression that returns an Application object.


NameRequired/OptionalData TypeDescription
DocRequiredDocumentThe current publication.
CancelRequiredBooleanFalse when the event occurs. If the event procedure sets this parameter to True, the publication is not printed when the procedure finishes running.


The BeforePrint event fires only after the document is fully loaded and the onload events have returned. Printing does not occur until the event handler is executed.

For more information about using events with the Application object, see Using Events with the Application Object.


The following Microsoft Visual Basic for Applications (VBA) macro shows how to handle the BeforePrint event. It displays a message notifying the user that the document is about to be printed.

Visual Basic for Applications
Private Sub pubApplication_BeforePrint(ByVal Doc As Document, Cancel As Boolean )
    MsgBox "Printing of " & Doc.Name & " is about to occur ."
End Sub

For this event to occur, you must place the following line of code in the General Declarations section of your module.

Visual Basic for Applications
Private WithEvents pubApplication As Application

Then run the following initialization procedure.

Visual Basic for Applications
Public Sub Initialize_pubApplication()
    Set pubApplication = Publisher.Application
End Sub

Community Additions

© 2014 Microsoft