
If an auto macro exists in a document and the attached template, only the auto macro stored in the document will execute. For example, event procedures in the Normal template occur only if the attached template is the Normal template. Unlike auto macros, event procedures in the Normal template don't have a global scope. The following example shows a Close event procedure in a document project that runs only when that document is closed. The following example shows a New event procedure in the Normal project that will run when a new document based on the Normal template is created. An empty subroutine for the selected event is added to the class module.Īdd the Visual Basic instructions you want to run when the event occurs. Select an event from the Procedure drop-down list box. Select Document from the Object drop-down list box.An empty subroutine for the New event is added to the class module.

(In Folder view, ThisDocument is located in the Microsoft Word Objects folder.) Under your Normal project or document project in the Project Explorer window, double-click ThisDocument.

You write procedures to respond to these events in the class module named "ThisDocument." Use the following steps to create an event procedure.

The Document object supports several events that enable you to respond to the state of a document.
