Putting Template Macros in a Document

by Allen Wyatt
(last updated February 19, 2019)

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 Office 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

Specifying Font Styles

Fonts, by default, come with one or more styles that define variations of how that font is displayed in your document. ...

Discover More

Calculating Months for Billing Purposes

Different businesses have different ways to calculate elapsed time for billing purposes. Figuring out a formula that ...

Discover More

Excel 2016 Filters and Filtering (Table of Contents)

Excel provides two ways to filter your data so that only what you want to see is displayed. Discover how filtering works ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Moving the Insertion Point in a Macro

One of the common things done in macros is to somehow "process" documents, which often means moving the insertion point ...

Discover More

Determining if Caps Lock is On

If your macro needs to determine the status of the Caps Lock key, you need the code in this tip. Just use the Information ...

Discover More

Counting Open Document Windows

When creating macros, it is sometimes necessary to know how many documents are open in Word. This is relatively easy to ...

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}] 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 9 - 8?

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.

Newest Tips
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.