Gurus needed! I'm trying to use a Word class object in order to
capture events in Word. Here's what I have, but the event code
appWord_BeforeD ocumentSave... doesn't ever fire.
In a Class Module +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++++++++++++
Public WithEvents appWord As Word.Applicatio n
Public WithEvents docWord As Word.Document
Public Sub appWord_Documen tBeforeSave(ByV al Doc As Word.Document,
SaveAsUI As Boolean, Cancel As Boolean)
MsgBox "This record is locked. You cannot save this file.", _
vbInformation + vbOKOnly, "Locked Record"
Cancel = True
End Sub
Public Sub OpenNewDocument (strFileName As String)
Set docWord = appWord.Documen ts.Open(strFile Name)
End Sub
Public Sub Class_Initializ e()
Set appWord = New Word.Applicatio n
appWord.Visible = True
End Sub
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++
Then in my regular code module
+++++++++++++++ +++++++++++++++ +++++++++++++++ ++
Public Function OpenFile()
On Error GoTo Err_OpenFile
Dim frm As Form
Dim myWord As clsMSWord
Dim strFile As String
Set frm = Screen.ActiveFo rm
If frm![EventsSub].Form!FileType = "doc" Then
Set myWord = New clsMSWord
strFile = frm![EventsSub].Form.txtLinkFi lePath
myWord.OpenNewD ocument (strFile)
Etc....
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++
This creates an instance of the class and opens Word and the file.
However, I cannot get the _BeforeDocument Save event to work.
Am I completely delusional or should there be a way to do this?
Thanks!
capture events in Word. Here's what I have, but the event code
appWord_BeforeD ocumentSave... doesn't ever fire.
In a Class Module +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++++++++++++
Public WithEvents appWord As Word.Applicatio n
Public WithEvents docWord As Word.Document
Public Sub appWord_Documen tBeforeSave(ByV al Doc As Word.Document,
SaveAsUI As Boolean, Cancel As Boolean)
MsgBox "This record is locked. You cannot save this file.", _
vbInformation + vbOKOnly, "Locked Record"
Cancel = True
End Sub
Public Sub OpenNewDocument (strFileName As String)
Set docWord = appWord.Documen ts.Open(strFile Name)
End Sub
Public Sub Class_Initializ e()
Set appWord = New Word.Applicatio n
appWord.Visible = True
End Sub
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++
Then in my regular code module
+++++++++++++++ +++++++++++++++ +++++++++++++++ ++
Public Function OpenFile()
On Error GoTo Err_OpenFile
Dim frm As Form
Dim myWord As clsMSWord
Dim strFile As String
Set frm = Screen.ActiveFo rm
If frm![EventsSub].Form!FileType = "doc" Then
Set myWord = New clsMSWord
strFile = frm![EventsSub].Form.txtLinkFi lePath
myWord.OpenNewD ocument (strFile)
Etc....
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++
This creates an instance of the class and opens Word and the file.
However, I cannot get the _BeforeDocument Save event to work.
Am I completely delusional or should there be a way to do this?
Thanks!
Comment