Putting Template Macros in a Document

Written by Allen Wyatt (last updated October 12, 2023)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


7

Neil has created a template that includes many macros used in the development of a report based on the template. When his contractors create a new document based on the template, the macros stay in the template. Neil wonders how to get the macros to "travel" with the document created from the template so he can continue to utilize the macros when the document is sent by the contractor to his office.

When you create a document based on a template, Word shows that template as "attached" to the document. Since the macros are in the template and the template is attached to the document, any macros in the template are available to the document whenever it is open. Thus, there is no need for the document to contain the macros since they are already available through the template.

The rub comes in when you transfer the document to another computer, such as a computer "back at the office." When you open the document, Word checks for the attached template at the indicated path as stored with the document. When it doesn't find it, that means the template isn't available and the macros, therefore, cannot be accessed.

Knowing this is how Word works with macros in the template leads to a solution, though. All you need to do is when you open the document, reattach the template. You should have, at your office, the same template that is being used by your contractors in the field. It is, no doubt, in a different location on your system than it is on those in the field. Reattach the template by following the steps in the tip entitled Changing the Attached Template.

If you find yourself needing to do this quite often, you might consider creating a macro on the home-office computers to do the reattachment for you. This can be very simple, such as this:

Sub AttachTemplate()
    Const Target_Template As String = "C:\PathToTemplate\MyTemplate.dotm"

    ActiveDocument.AttachedTemplate = Target_Template
End Sub

You'll want to make sure that the Target_Template constant is set to the full path to the template you want to use; the same one used by the contractors out in the field. Make sure the macro is in the Normal template, and you will be all set. You can even assign the macro to the Quick Access Toolbar or give it a shortcut key. Whenever the macro is executed, the attached template for the current document is set to the proper template, and the macros in that template will then be accessible.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13621) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Adding Leading Zeroes to ZIP Codes

Import a bunch of ZIP Codes into Excel, and you may be surprised that any leading zeroes disappear. Here's a handy little ...

Discover More

Using Graphics to Represent Data Series

You can spice up your bar chart by using a graphic, of your choosing, to construct the bars. This tip shows how easy it ...

Discover More

Template Changing On Its Own

When you attach a template to a document, you expect that template to stay attached. When you share the document with ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Hiding Macros

Don't want a particular macro to be visible in the Macros dialog box? Once you understand the criteria that Word uses ...

Discover More

Inserting a Paragraph from within a Macro

Macros are often used to process documents, resulting in changes of one manner or another. If you need your macro to add ...

Discover More

Bumping Numbers in a Document

If your documents include words that contain numbers (such as a list of parts numbers) you may need a way to increment ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is one less than 9?

2019-02-25 14:06:26

Mechie

Does Word work differently than Excel?

I do 20x more in Excel than Word. I have an Excel Macro Enabled Template (.xltm). When a new document is generated from that template (by a double click in File Explorer, or via shortcut to said file), the new document includes the macros, AS LONG AS one saves the new file as a macro enabled file that is (.xlsm, not .xlsx). Sounds to me that this is what Neil was looking for with his question of, "how to get the macros to "travel" with the document created from the template". Word has the corresponding file extensions.

I know that there are pros and cons to macro enabled files (but that's another topic).


2019-02-19 12:53:25

Allen

Thank you, Andrew. Definitely a "too close to the forest to see the trees" issue. I appreciate it.

-Allen


2019-02-19 10:45:21

Andrew

indicted==>indicated


2019-02-18 10:30:22

Jay

Does ActiveDocument.AttachedTemplate have advantages over AddIns.Add?

AddIns.Add ("C:\PathToTemplate\MyTemplate.dotm")


2019-02-18 09:53:16

Jay

Does ActiveDocument.AttachedTemplate have advantages over AddIns.Add?

AddIns.Add ("C:\PathToTemplate\MyTemplate.dotm")


2019-02-17 11:09:03

Allen

Hugh,

Thanks for the feedback. Some people like to think there is an editorial staff behind the scenes in the production of this newsletter and the almost 14,000 tips on the Tips.Net sites. There is not; there is only me. (Would that I could afford the staff!) Sometimes I miss things, despite my best intentions or efforts. Thus the reason I appreciate your feedback.

I have corrected the first error point out (the missing word was "get"), but I cannot see the second error you reference; it reads fine to me. Perhaps I am too close to the forest to see the trees, but what is it that you feel is missing or incorrect in the second two-second quote you note?

-Allen


2019-02-16 06:21:04

Hugh Tannenbaum

Good morning. I have been an avid reader of your Word and Excel Tips for many years and have learned so much from these. Thank you. Lately, though, I've been surprised by the number of errors in some of these tips. In this tip, for example, there are two glaring errors that threw me off as this is not what I expect from you. Specifically: "Neil wonders how to the macros to "travel" with the document created from the template so he can continue to utilize the macros when the document is sent by the contractor to his office." is not correct nor is "When you open the document, Word checks for the attached template at the indicted path as stored with the document. When it doesn't find it, that means the template isn't available and the macros, therefore, cannot be accessed." I know typos and minor errors can occur but I expect proofreading can catch them. Again, the gist of what you're saying is clear enough but the errors are jarring.


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.