Word has Document_Close, Document_New and Document_Open events (amongst others), and you can add more. Using Events requires that you instantiate the app object class. To do this, create a new class module to register your events. At the top of the module put:
Code:
Public WithEvents wdApp As Word.Application
Public WithEvents wdDoc As Word.Document
Then, in a normal code module, put:
Code:
Dim wdAppClass As New ThisApplication
Public Sub AutoExec()
Set wdAppClass.wdApp = Word.Application
End Sub
This will allow you to get events from your Word document. For example, you can use the selection change event and test if the selection is in a header or footer:
Code:
Private Sub wdDoc_WindowSelectionChange(ByVal Sel As Selection)
If Selection.Information(WdInformation.wdInHeaderFooter) = True Then
MsgBox "I'm in a header or footer!"
Else
MsgBox "I'm NOT in a header or footer!"
End If
End Sub
or, more usefully, to ensure a document with formfields is protected before printing:
Code:
Private Sub wdApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
With Doc
If .FormFields.Count > 0 Then _
If .ProtectionType = wdNoProtection Then _
.Protect Type:=wdAllowOnlyFormFields, noreset:=True
End With
End Sub
For further info, see:
http://msdn.microsoft.com/en-us/libr...ffice.10).aspx