K
Kristi
I have a document protected for forms which I will be emailing out. I need
the users to complete one of the fields before closing the document.
Using the Help files, I created a macro to run on the DocumentBeforeClose
event. The Help files stated that you must create a separate Class Module to
post the code in. And it also said to create an event handler macro that
must be run before it will work.
I did these things and the code works after running the event handler macro.
However, do you have to run that macro every time the document is opened?
The code will not execute in subsequent openings of the file, unless the
event handler macro is run again. Isn't there a way to make everything run
smoothly without having to run that macro every time the document is opened?
Here is the code. I have a Class Module called EventClassModule with the
following code (I also have a DocumentOpen event, in the same class module
and having the same issues):
Public WithEvents appWord As Word.Application
-----
Private Sub appWord_DocumentBeforeClose _
(ByVal Doc As Document, _
Cancel As Boolean)
Dim BusJust
If ActiveDocument.FormFields("txt_BusJust").Result = "" Then
MsgBox ("You must complete the" & Chr(10) & "BUSINESS
JUSTIFICATION(S)" & Chr(10) _
& "field before closing this document.")
Cancel = True
ActiveDocument.Bookmarks("txt_BusJust").Select
End If
-----
Private Sub appWord_DocumentOpen(ByVal Doc As Document)
ActiveDocument.ActiveWindow.View.ShowHiddenText = False
End Sub
Then, in the NewMacros module, I have the following code:
Sub Register_Event_Handler()
Set X.appWord = Word.Application
End Sub
Thanks for your help.
Kristi
the users to complete one of the fields before closing the document.
Using the Help files, I created a macro to run on the DocumentBeforeClose
event. The Help files stated that you must create a separate Class Module to
post the code in. And it also said to create an event handler macro that
must be run before it will work.
I did these things and the code works after running the event handler macro.
However, do you have to run that macro every time the document is opened?
The code will not execute in subsequent openings of the file, unless the
event handler macro is run again. Isn't there a way to make everything run
smoothly without having to run that macro every time the document is opened?
Here is the code. I have a Class Module called EventClassModule with the
following code (I also have a DocumentOpen event, in the same class module
and having the same issues):
Public WithEvents appWord As Word.Application
-----
Private Sub appWord_DocumentBeforeClose _
(ByVal Doc As Document, _
Cancel As Boolean)
Dim BusJust
If ActiveDocument.FormFields("txt_BusJust").Result = "" Then
MsgBox ("You must complete the" & Chr(10) & "BUSINESS
JUSTIFICATION(S)" & Chr(10) _
& "field before closing this document.")
Cancel = True
ActiveDocument.Bookmarks("txt_BusJust").Select
End If
-----
Private Sub appWord_DocumentOpen(ByVal Doc As Document)
ActiveDocument.ActiveWindow.View.ShowHiddenText = False
End Sub
Then, in the NewMacros module, I have the following code:
Sub Register_Event_Handler()
Set X.appWord = Word.Application
End Sub
Thanks for your help.
Kristi