Using events with the Document object (Publisher)
The Document object supports seven events: BeforeClose, Open, Redo, ShapesAdded, ShapesRemoved, Undo, and WizardAfterChange. You write procedures to respond to these events in the class module named ThisDocument.
Use the following steps to create an event procedure:
Under your publication project in the Project Explorer window, double-click ThisDocument. In Folder view, ThisDocument is located in the Microsoft Publisher Objects folder.
Select Document from the Object drop-down list box.
Select an event from the Procedure drop-down list box. An empty subroutine is added to the class module.
Add the Visual Basic instructions that you want to run when the event occurs.
Example
This example shows an Open event procedure that displays a message when a publication is opened.
Private Sub Document_Open()
MsgBox "This publication is copyrighted."
End Sub
The following example shows a BeforeClose event procedure that prompts the user for a yes or no response before closing a document.
Private Sub Document_BeforeClose(Cancel As Boolean)
Dim intResponse As Integer
intResponse = MsgBox("Do you really want to close " _
& "the document?", vbYesNo)
If intResponse = vbNo Then Cancel = True
End Sub
Note
For information about creating event procedures for the Application object, see Using events with the Application object.
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.