Application Level

EventDescription36516131007
DocumentBeforeCloseOccurs before any open document is closed. Cancel does not work ?YYYYY
DocumentBeforePrintOccurs before any open document is printed.YYYYY
DocumentBeforeSaveOccurs 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 ?
YYYYY
DocumentChangeOccurs 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
YYYYY
DocumentOpenOccurs when an existing document is opened.YYYYY
DocumentSyncOccurs when the local copy of a document is synchronized with a copy on the server that is part of a document workspace.YYYYY
EPostageInsertOccurs when the user inserts an electronic postage into a document.YYYYY
EPostageInsertExOccurs when a user inserts electronic postage into a document.YYYYY
EPostagPropertyDialogOccurs 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.YYYYY
MailMergeAfterMergeOccurs after all the records in a mail merre have been merged successfully.YYYYY
MailMergeAfterRecordMergeOccurs after each record in the data source has been successfully merged.YYYYY
MailMergeBeforeMergeOccurs when a merge is executed before any records merge.YYYYY
MailMergeBeforeRecordMergeOccurs as a merge is executed for the individual records in a merge.YYYYY
MailMergeDataSourceLoadOccurs when the data source is loaded for a mail merge.YYYYY
MailMergeDataSourceValidateOccurs when a user performs address verification by clicking Validate in the Mail Merge Receipts dialog box.YYYYY
MailMergeDataSourceValidate2Occurs when a user validates mail merge recipients by clicking Validate Address Link button in the Mail Merge Receipts dialog box.YYYYY
MailMergeWizardSendToCustomOccurs when the custom button is clicked on step 6 of the mail merge wizard.YYYYY
MailMergeWizardStateChangeOccurs when a user changes from one specified step to another specified step in the mail merge wizard.YYYYY
NewDocumentOccurs when a new document is created.YYYYY
ProtectedViewWindowActivateOccurs when any protected view window is activate.YYYY 
ProtectedViewWindowBeforeCloseOccurs immediately before a protected view window or a document in a protected view window closes.YYYY 
ProtectedViewWindowBeforeEditOccurs immediately before editing is enabled on the document in the specified protected view windowYYYY 
ProtectedViewWindowDeactivateOccurs when a protected view window is deactivated.YYYY 
ProtectedViewWindowOpenOccurs when a protected view window is opened.YYYY 
ProtectedViewWindowSizeOccurs when a protected view window is sized (?)YYYY 
QuitOccurs when the user quits Word.YYYYY
StartupRedundant. 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.YYYY 
WindowActivateOccurs when the user moves focus to another open document.YYYYY
WindowBeforeDoubleClickOccurs before any editing area of a document is double clicked.YYYYY
WindowBeforeRightClickOccurs before the user right clicks on any editing area of a document.YYYYY
WindowDeactivateOccurs when the user moves focus away from the open window in any document.YYYYY
WindowSelectionChangeOccurs when the user changes the current selection on any document.YYYYY
WindowSizeOccurs after the application window has been resized or moved.YYYYY
XMLSelectionChangeOccurs when the parent xml node of the current selection changes.YYYYY
XMLValidationErrorOccurs when there is a validation error in the xml documentYYYYY

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