You are going to need to create a template addin containing an event handler.
'Put this code in a standard code module:
Public AppEvents As New clsEvents
Public Sub AutoExec()
Set AppEvents.WordApp = Word.Application
End Sub
'Put this code in a class module named clsEvents:
Public WithEvents WordApp As Word.Application
Private Sub WordApp_DocumentOpen(ByVal strDocName As Word.Document)
MsgBox strDocName & " is opening"
End Sub
Private Sub WordApp_DocumentBeforeClose(ByVal strDocName As Word.Document, ByRef Cancel As Boolean)
MsgBox strDocName & " is closing"
End Sub
Private Sub WordApp_Quit()
MsgBox "WordApp_Quit"
End Sub
You can probably put your code in the DocumentBeforeClose event.
|