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.
An empty subroutine is added to the class module.
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 on creating event procedures for the Application object, see Using Events with the Application Object.