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

Protecting Formulas in Control-Linked Cells

Form controls can be a great way to get information into a worksheet. They are designed to be linked to a cell so that ...

Discover More

Updating an Entire TOC from a Macro

The TOC (Table of Contents) is generated by a field. This field may be updated in a macro using a single command line.

Discover More

Making Ignore All Work for a Document on All Systems

When you tell Word's spell checker to ignore all instances of a misspelling, you may expect that the misspelling will be ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Resetting Character Formatting in a Macro

Shortcut keys are a great way to apply styles to text in a document. You can easily create a shortcut key assignment for ...

Discover More

Reversing All the Paragraphs in a Document

Documents consist of a series of paragraphs, arranged in the order in which you need them. What if you need to reverse ...

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

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.