0
votes

I'm just wondering how to prevent (stop) a user from saving a document (just "Save", "Save As" is okay). I have a .docm that I'm using as a template, where the user just fills in three fields. I don't want them to accidentally fill it in, then save over the template.

I've seen a few SO threads that give code, but when I put the following in "ThisDocument" under "Microsoft Word Objects", nothing happens when I hit save:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    MsgBox ("Please 'Save As' instead.")
    Debug.Print "Someone tried to save."
    Cancel = True
End Sub

I'm expecting when I hit the save icon (or CTRL+S) the messagebox to pop up. ..that doesn't happen (nor does the debug.print line work). What am I overlooking?

Related question: Should I just forget doing the above, and just create a true template document (.dotm)?

1

1 Answers

0
votes

Yes, your users should be creating new documents from a template. Save the template in the users' Templates folder so that they can access it via File/New when they want to create a new document...

Concerning the code you show: Workbook is for Excel and won't trigger in Word. In Word the event is Document_BeforeSave and you'd want to set the SaveAsUI parameter to True to force the dialog box to show.