I'm writing a custom Word template which does some processing upon saving the current document.
In Office2007, to save a document you can use the Save and the Save As functions, and handle the events with the FileSave and FileSaveAs macros.
But when the user hovers over the SaveAs option, other sub-options are displayed: Save as a document, as a Word template, as Word 97-2003 document, etc. These sub-options don't seem to have their own events, but I'd like to know when the user uses them.
So I came up with the idea to use the DocumentBeforeSave event, but then I still have to figure out if the save occured with the standard Save/SaveAs options or with the sub-options.
I thought about setting a variable to True in the Save/SaveAs functions, which the DocumentBeforeSave event would check to see if one of the normal save methods occured, then it would set the variable back to False.
But after experimenting with different methods, I can't figure out how I can pass the value of a variable between ThisDocument and the Class Module which has the BeforeSave event.
Any ideas? Thanks!
Edit: Example code that doesn't work:
ThisDocument:
Public pSSave As Boolean
Public Property Get SSave() As Boolean
SSave = pSSave
End Property
Public Property Let SSave(Value As Boolean)
pSSave = Value
End Property
Sub FileSave()
Me.SSave = True
If SSave = True Then
MsgBox "True"
End If
Application.ActiveDocument.Save
If SSave = True Then
MsgBox "True"
End If
End Sub
Class Module:
Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
If Application.ActiveDocument.SSave = False Then
MsgBox "False"
End If
End Sub
The class module registration is done properly, I won't paste the code her.
The result displayed is True, False, True while theoretically, it should be True, True.
property let\get
in your class and using that property pass any value to your Class. Or just add additionalpublic variable
in your class which could take that value you pass – Kazimierz Jawor