![]() |
|
#1
|
|||
|
|||
|
I have utilized BeforeClose, BeforePrint, and BeforeSave functions in EXCEL, but I do not see them available for WORD VBA projects.
![]() Is there a way of creating these using a new CLASS definition?
|
|
#2
|
||||
|
||||
|
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 Code:
Dim wdAppClass As New ThisApplication Public Sub AutoExec() Set wdAppClass.wdApp = Word.Application End Sub 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 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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Thank you so much. GREAT reference link.
|
|
|
|