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 you want to run when the event occurs.
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
For information on creating event procedures for the Application object, see Using Events with the Application Object .