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 2021


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 2021.

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

Printing Document Properties

Word maintains quite a bit of information about a document in a special collection of items called "properties." You can ...

Discover More

Adjusting Column Widths on Joined Tables

Each table in a document can have different numbers of columns and different widths for columns. If you want to join two ...

Discover More

Automatic Row Height for Wrapped Text

When you format a cell so that the information within it can wrap to multiple lines, you may be surprised if Excel ...

Discover More

Discover the Power of Microsoft Office This beginner-friendly guide reveals the expert tips and strategies you need to skyrocket your productivity and use Office 365 like a pro. Mastering software like Word, Excel, and PowerPoint is essential to be more efficient and advance your career. Simple lessons guide you through every step, providing the knowledge you need to get started. Check out Microsoft Office 365 For Beginners today!

More WordTips (ribbon)

Accessing Paragraphs in a Macro

Need to process a document, paragraph by paragraph, in a macro? It's easy to do once you understand that Word's object ...

Discover More

Repaginating in a Macro

When creating a macro that extensively processes a document, you may need to periodically force Word to repaginate the ...

Discover More

Dissecting a String

Want to pull a string apart in a macro? It's easy using the string functions introduced in this tip.

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 seven less than 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.

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.