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

Using the Insert Key to Insert Text

The Insert key can be used for different purposes, depending on how you configure the program. This tip explains those ...

Discover More

Setting the Calculation Default

Excel can recalculate your worksheets either automatically or manually. The default is to calculate them automatically, ...

Discover More

Copying the Quick Access Toolbar

Customization of Word is done, largely, through what you add to or remove from the Quick Access Toolbar. When you have ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Determining the Month of the Year

Your macro code may need to determine the month of the year represented by a particular date. You can find the desired ...

Discover More

Determining an Integer Value

One of the math functions you can use in your macros is the Int function. It provides a way for you to derive an integer ...

Discover More

Selecting to the Next Punctuation Mark

Writing macros often involves selecting different parts of your document so that some sort of processing can be ...

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 2 + 2?

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.