Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Feb 5 '13 at 15:46

This question came from our site for professional and enthusiast programmers.

1  
this isn't about programming but usage of microsoft products. –  Gung Foo Feb 5 '13 at 12:55
    
Perhaps I should have been more specific. Is there a way to make way to trigger a macro based on the save event that happens when a user closes a document and is prompted to save? My on save event macro on seems to fire when the user clicks save. Also, is there a trick to using the on close event to trigger a macro? –  MechEng Feb 5 '13 at 13:19
    
This discussion may be helpful: support.microsoft.com/kb/918064 –  burrowsrjl Feb 5 '13 at 19:04

2 Answers 2

up vote 1 down vote accepted

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:

ActiveDocument.AttachedTemplate.Saved=True
ActiveDocument.AttachedTemplate=""

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.

share|improve this answer

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

Author: Jay Freedman Source: http://answers.microsoft.com/en-us/office/forum/office_365hp-word/i-never-want-to-save-changes-to-template-from-a/f1cc78f8-2f2f-4c45-a3fb-731a9105a5a8

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.