Share via

Use template macro to specify default save format only for documents opened from that template?

Anonymous
2012-06-15T19:18:13+00:00

We're transitioning to a new macro-enabled template for a commonly used form at my workplace. Users need to save any new documents created from the template as .docm (macro-enabled document) files so they don't lose the macros. However, the default format in word is .docx . We've already had a few issues where someone accidentally saves their new document as a .docx and I have to open it up, paste the macros from the template into the document, and save the document again as a .docm

I would like to add code to the template so that when a new document is opened from the template, the default save format for that document is set to .docm. I do not want to go around and change the default file save format on each person's computer. Is there a way to specify the save format for only the active document?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Jay Freedman 207.7K Reputation points Volunteer Moderator
2012-06-16T02:22:45+00:00

To reinforce what Doug has said, it should very rarely be necessary to have macros in a document. The macros should be only in the document's base template. The most common time this is not true is when the template won't be accessible from the computer that's opening the document (e.g., a laptop that may be disconnected from the company network) and the local Normal.dotm template is attached instead. Even in that case, it would be better to have a copy of the template downloaded to the computer's local drive so that it is always available.

The main reason for this is Word's (IMHO clumsy) handling of macro security. Unless the document is stored in a "trusted location" and the macro setting in the Trust Center is properly set, upon opening the document the macros will be disabled. Depending on the settings, there may or may not be a notification that the macros are disabled.

One other point: Setting the Save As type to .docm DOES NOT copy the macros from the template to the document. You would need to separately intercept the Save As function and force it to copy the macros over. For that to work, you have to go into the Trust Center dialog ON EACH COMPUTER and turn on the option to "Trust access to the VBA project object model", which is a serious security hole even worse than saving macros in a document.

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2012-06-16T00:29:27+00:00

We're transitioning to a new macro-enabled template for a commonly used form at my workplace. Users need to save any new documents created from the template as .docm (macro-enabled document) files so they don't lose the macros. However, the default format in word is .docx . We've already had a few issues where someone accidentally saves their new document as a .docx and I have to open it up, paste the macros from the template into the document, and save the document again as a .docm

I would like to add code to the template so that when a new document is opened from the template, the default save format for that document is set to .docm. I do not want to go around and change the default file save format on each person's computer. Is there a way to specify the save format for only the active document?

Assuming that the template is available to a machine on which the document is opened, the macros in the template should be available for use in the document even if it is saved as a .docx file as a reference to the template will be created if it is available.

If that is not always going to be the case, then I would suggest the use of an autonew macro in the template that asks the user for the filename underwhich they want to save the document and when they supply that filename, the code will save the document in the required format.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2012-06-18T15:34:34+00:00

    The template is on the company server and accessible to all of the computers. Based on what the two of you said I tried saving the new document in .docx format and indeed there is a reference to the template and the macros still work! Maybe the problem was people opening the template for editing (right-click>open) rather than as a new document. The macro template project got pushed on me rather suddenly and I had to dive in without any previous experience with macros. Anyway, from trial and error and help from the two of you I think I've got an adequate understanding of what's going on now. Thanks for the help.

    Was this answer helpful?

    0 comments No comments