Is there a way to never save templates in Word? We have a lot of templates that we use to create standard documents. When a document based on one of these templates is closed, the user is asked if they want to save changes to the template. I wrote a macro that prevents this, but only if the main document was saved just prior to closing. Is there a way to prevent the template from ever being saved/changed from a document that is based in it?
I reviewed the link above and it lead me to the answer. I am creating the new documents with a macro that loads the proper template. i just added two lines to the macro:
The first line makes the template appear to be saved (so that user is not prompted). The second line breaks the connectioun to the template. (this sets the associated template to "Normal".
This appears to be a good solution to ensure that the user never accidentally saves any formatting changes back to the master template.
There is no setting to suppress the prompt, but VBA can do it.
In the macro editor, select the Normal project and click Insert > Class Module. In the Properties pane, change the name of the class module to EventClassModule. (If you don't see the Properties pane, press F4 or click View > Properties Window.)
In the code window for the class module, paste this code:
Public WithEvents App As Word.Application Private Sub App_DocumentBeforeSave(ByVal Doc As Document, _ SaveAsUI As Boolean, Cancel As Boolean) If Doc Is ActiveDocument And ActiveDocument.AttachedTemplate <> ActiveDocument Then Doc.AttachedTemplate.Saved = True ' avoid saving template End If End Sub
Also in the Normal project, add a regular module (Insert > Module) and add this code to it:
Dim X As New EventClassModule Sub AutoExec() Set X.App = Word.Application End Sub Sub AutoExit() Set X = Nothing End Sub