I really don\'t know the syntax of the DocumentBeforeClose event. Following this page, I should create a class module called \'EventClassModule\' (see also this article). So I d
I tried the same thing! Actually it works for me. I have this in a class module named EventClassModule
Public WithEvents appWord As Word.Application
Private Sub appWord_DocumentBeforeClose _
(ByVal Doc As Document, _
Cancel As Boolean)
'Here is the code you want to do before it close
MsgBox "WORKING!"
End Sub
And in a module (not a class module) I have this
Dim X As New EventClassModule
Sub AutoExec()
'Call any other sub or function you want
Call Register_Event_Handler
End Sub
Sub Register_Event_Handler()
Set X.appWord = Word.Application
End Sub
AutoExec is called as soon as the document is loaded. So it calls the sub Register_Event_Handler to register the object X (which is a object EventClassModule, the class module created). So X will be annonced that the document is about to close
hope it helps!
X
is an instance of the class you created (EventClassModule
)
Your problem is that .App
is not a property of EventClassModule
. Change
Set X.App = Word.Application
to the property you defined in your class
Set X.appWord = Word.Application