by Allen Wyatt
(last updated February 19, 2019)
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.
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!
If you develop a macro to process your document, you may want the macro to save the document to disk. This is easily done ...Discover More
When developing a macro, you may need to swap the values in two variables. It's simple to do using the technique in this tip.Discover More
When creating macros, you often need to offer a series of choices to a user. This tip demonstrates how easy it is to ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.