Application Level
Event | Description | 365 | 16 | 13 | 10 | 07 |
DocumentBeforeClose | Occurs before any open document is closed. Cancel does not work ? | Y | Y | Y | Y | Y |
DocumentBeforePrint | Occurs before any open document is printed. | Y | Y | Y | Y | Y |
DocumentBeforeSave | Occurs before any open document is saved. Is this fired after the decision to save or not? Can you make changes to the document in this event ? | Y | Y | Y | Y | Y |
DocumentChange | Occurs when the focus switches back and forth between Word and other applications. Occurs when a new document is created, when an existing document is opened, or when another document is made the active document. Entering a header can fire this event. Togglying protection can fire this event | Y | Y | Y | Y | Y |
DocumentOpen | Occurs when an existing document is opened. | Y | Y | Y | Y | Y |
DocumentSync | Occurs when the local copy of a document is synchronized with a copy on the server that is part of a document workspace. | Y | Y | Y | Y | Y |
EPostageInsert | Occurs when the user inserts an electronic postage into a document. | Y | Y | Y | Y | Y |
EPostageInsertEx | Occurs when a user inserts electronic postage into a document. | Y | Y | Y | Y | Y |
EPostagPropertyDialog | Occurs when the user click E-Postage Properties (on the Labels and Envelopes dialog box) or Print Electronic Postage. This allows a third party tool to intercept and show its Properties dialog box. | Y | Y | Y | Y | Y |
MailMergeAfterMerge | Occurs after all the records in a mail merre have been merged successfully. | Y | Y | Y | Y | Y |
MailMergeAfterRecordMerge | Occurs after each record in the data source has been successfully merged. | Y | Y | Y | Y | Y |
MailMergeBeforeMerge | Occurs when a merge is executed before any records merge. | Y | Y | Y | Y | Y |
MailMergeBeforeRecordMerge | Occurs as a merge is executed for the individual records in a merge. | Y | Y | Y | Y | Y |
MailMergeDataSourceLoad | Occurs when the data source is loaded for a mail merge. | Y | Y | Y | Y | Y |
MailMergeDataSourceValidate | Occurs when a user performs address verification by clicking Validate in the Mail Merge Receipts dialog box. | Y | Y | Y | Y | Y |
MailMergeDataSourceValidate2 | Occurs when a user validates mail merge recipients by clicking Validate Address Link button in the Mail Merge Receipts dialog box. | Y | Y | Y | Y | Y |
MailMergeWizardSendToCustom | Occurs when the custom button is clicked on step 6 of the mail merge wizard. | Y | Y | Y | Y | Y |
MailMergeWizardStateChange | Occurs when a user changes from one specified step to another specified step in the mail merge wizard. | Y | Y | Y | Y | Y |
NewDocument | Occurs when a new document is created. | Y | Y | Y | Y | Y |
ProtectedViewWindowActivate | Occurs when any protected view window is activate. | Y | Y | Y | Y | |
ProtectedViewWindowBeforeClose | Occurs immediately before a protected view window or a document in a protected view window closes. | Y | Y | Y | Y | |
ProtectedViewWindowBeforeEdit | Occurs immediately before editing is enabled on the document in the specified protected view window | Y | Y | Y | Y | |
ProtectedViewWindowDeactivate | Occurs when a protected view window is deactivated. | Y | Y | Y | Y | |
ProtectedViewWindowOpen | Occurs when a protected view window is opened. | Y | Y | Y | Y | |
ProtectedViewWindowSize | Occurs when a protected view window is sized (?) | Y | Y | Y | Y | |
Quit | Occurs when the user quits Word. | Y | Y | Y | Y | Y |
Startup | Redundant. Occurs when Word is first opened and can only be handled by an add-in. This event is raised when the application is started up before any documents are loaded and before an automation executable can establish an event handler. This event is not fired when files are opened up from URL links that display the 'File Download' dialog box. Add-ins do not need to use this because you have the ThisAdd-in_Startup event which does the same thing. COM Add-ins have the OnConnection. | Y | Y | Y | Y | |
WindowActivate | Occurs when the user moves focus to another open document. | Y | Y | Y | Y | Y |
WindowBeforeDoubleClick | Occurs before any editing area of a document is double clicked. | Y | Y | Y | Y | Y |
WindowBeforeRightClick | Occurs before the user right clicks on any editing area of a document. | Y | Y | Y | Y | Y |
WindowDeactivate | Occurs when the user moves focus away from the open window in any document. | Y | Y | Y | Y | Y |
WindowSelectionChange | Occurs when the user changes the current selection on any document. | Y | Y | Y | Y | Y |
WindowSize | Occurs after the application window has been resized or moved. | Y | Y | Y | Y | Y |
XMLSelectionChange | Occurs when the parent xml node of the current selection changes. | Y | Y | Y | Y | Y |
XMLValidationError | Occurs when there is a validation error in the xml document | Y | Y | Y | Y | Y |
Application Level Events
You must write your own event handler routines when you want to capture any of the Application events since these events are not enabled by default.
This can be done using the WithEvents keyword in a class module.
Create a new class module called "ApplicationEventClass"
Before you can use them you must create a new class module and declare an object of type Application with events.
Public WithEvents WordAppEvents As Application
After the new object has been declared with events, it appears in the Object box in the class module (top left).
When you select the new object in the Object box, the valid events for that object are listed in the Procedure box (top right).
However before the event handlers will run you must connect the declared object in the class module to the Application object.
You can do this from any module by using the following declaration, where "ApplicationEventsClass" is the name of the class module you created to enable the events
Public ApplicationClass As New ApplicationEventClass
After you have created the object variable you can set the ExcelAppEvents object of the EventClass to equal the Microsoft Excel application object.
Set ApplicationClass.ExcelAppEvents = Application
Once this has been assigned the events in the EventsClass will run whenever the events occur.
Event Procedures
Private Sub WordAppEvents_DocumentBeforeClose(ByVal Doc As Document, _
Cancel As Boolean)
End Sub
Private Sub WordAppEvents_DocumentBeforePrint(ByVal Doc As Document, _
Cancel As Boolean)
End Sub
Private Sub WordAppEvents_DocumentBeforeSave(ByVal Doc As Document, _
SaveAsUI As Boolean, _
Cancel As Boolean)
End Sub
Private Sub WordAppEvents_DocumentChange()
End Sub
Private Sub WordAppEvents_DocumentOpen(ByVal Doc As Document)
End Sub
Private Sub WordAppEvents_DocumentSync(ByVal Doc As Document, _
ByVal SyncEventType As Office.MsoSyncEventType)
End Sub
Private Sub WordAppEvents_EPostageInsert(ByVal Doc As Document)
End Sub
Private Sub WordAppEvents_EPostageInsertEx(ByVal Doc As Document, _
ByVal cpDeliveryAddrStart As Long, _
ByVal cpDeliveryAddrEnd As Long, _
ByVal cpReturnAddrStart As Long, _
ByVal cpReturnAddrEnd As Long, _
ByVal xaWidth As Long, _
ByVal yaHeight As Long, _
ByVal bstrPrinterName As String, _
ByVal bstrPaperFeed As String, _
ByVal fPrint As Boolean, _
fCancel As Boolean)
End Sub
Private Sub WordAppEvents_EPostagePropertyDialog(ByVal Doc As Document)
End Sub
Private Sub WordAppEvents_MailMergeAfterMerge(ByVal Doc As Document, _
ByVal DocResult As Document)
End Sub
Private Sub WordAppEvents_MailMergeAfterRecordMerge(ByVal Doc As Document)
End Sub
Private Sub WordAppEvents_MailMergeBeforeMerge(ByVal Doc As Document, _
ByVal StartRecord As Long, _
ByVal EndRecord As Long, _
Cancel As Boolean)
End Sub
Private Sub WordAppEvents_MailMergeBeforeRecordMerge(ByVal Doc As Document, _
Cancel As Boolean)
End Sub
Private Sub WordAppEvents_MailMergeDataSourceLoad(ByVal Doc As Document)
End Sub
Private Sub WordAppEvents_MailMergeDataSourceValidate(ByVal Doc As Document, _
Handled As Boolean)
End Sub
Private Sub WordAppEvents_MailMergeWizardSendToCustom(ByVal Doc As Document)
End Sub
Private Sub WordAppEvents_MailMergeWizardStateChange(ByVal Doc As Document, _
FromState As Long, _
ToState As Long, _
Handled As Boolean)
End Sub
Private Sub WordAppEvents_NewDocument(ByVal Doc As Document)
End Sub
Private Sub WordAppEvents_Quit()
End Sub
Private Sub WordAppEvents_WindowActivate(ByVal Doc As Document, _
ByVal Wn As Window)
End Sub
Private Sub WordAppEvents_WindowBeforeDoubleClick(ByVal Sel As Selection, _
Cancel As Boolean)
End Sub
Private Sub WordAppEvents_WindowBeforeRightClick(ByVal Sel As Selection, _
Cancel As Boolean)
End Sub
Private Sub WordAppEvents_WindowDeactivate(ByVal Doc As Document, _
ByVal Wn As Window)
End Sub
Private Sub WordAppEvents_WindowSelectionChange(ByVal Sel As Selection)
End Sub
Private Sub WordAppEvents_WindowSize(ByVal Doc As Document, _
ByVal Wn As Window)
End Sub
Private Sub WordAppEvents_XMLSelectionChange(ByVal Sel As Selection, _
ByVal OldXMLNode As XMLNode, _
ByVal NewXMLNode As XMLNode, _
Reason As Long)
End Sub
This is raised when the selected xml element changes in a document with XML mappings
The new selection object is passed to this event.
It also passes the xmlnode object that was selected previously and the xmlnode that is now selected
It also passes a reason for the change in the shape of an enumeration - wdXMLSelectionChange.wdXMLSelectionChangeReasonDelete | ReasonInsert | ReasonMove
Private Sub WordAppEvents_XMLValidationError(ByVal XMLNode As XMLNode)
End Sub
This is raised when the xml in the document is not valid when compared to the schema associated with the document.
The node object corresponding to the invalid element is passed as a parameter.
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext