Creating macro templates and macro-enabled documents in Microsoft Word.

This article will guide you through the process of creating macro templates and macro-enabled documents in Microsoft Word.

NOTE: You can refresh your knowledge of the several file types that Microsoft Word works with, in this article.

Table of Contents

Creating a Macro-Enabled template.

1. Creating a macro in a document.

2. Use the "Save As" menu.

3. Save as a macro template file type.

4. Attach the template to a document.

5. Test the macros.



Creating a Macro-Enabled Document.

1.Create a new document.

2.Record a macro.

3.Store the Macro in the document.

4.Save the macro-enabled document.

5.Test the macros.


We've already talked about what macros are and how they can be created and used within a Microsoft Word document. What we didn't mention is that macros are also something that can be saved in, and then applied as, a document template. We will also cover how you can create a macro-enabled document in this article as well.

There are many file types to consider when using Microsoft Word, but in this article we will mainly focus on the .dotm(macro-enabled template) and the .docm(macro-enabled document) extensions.

What is a .dotm file?

A .dotm file is something that's known as a Macro-Enabled Word Template. In short this means that we can take an empty Word Document, record some macros in it, and then save it as a template to then later have it applied to other .docx files.

We can demonstrate how a Macro-Enabled Template can be created and applied to a .docx file below.

TIP: Before going through working with templates, you can familiarize yourself with what macros are and how to create them.


Let's use the macro that we have created in this article previously. Remember that we created and stored it within the document instead of the global template (Normal.dotm).

Consider This: If we had saved it to the global template, that would mean any new document that we create will have that macro loaded up automatically because it is saved to Normal.dotm (which is a template that is attached to all documents by default).

But if we create a new template file with that macro we can then attach it to another .docx document. Let's look at what that looks like in practice.

Consider the file that we have created that has a macro in it.

 


We can save this as a macro-enabled template or a .dotm file by clicking on File...


Then clicking on Save As...

 

Then Browse...

NOTE: At this point you will be presented with a Save As window, where you can select where you want to save your new template. Keep in mind that if the macro-enabled template is saved to an un-trusted location, the macros will not run If you try to open or attach the template from that same location.

Now name your new template.

 

Then click on the "Save as type" drop-down list and select the .dotm file format.

 

Click Save.

NOTE: You now have a template that can be "attached" to any .docx file.

Let's open a new document that doesn't have any macros attached.

 

We can attach the template that contains our custom macro to the new document. Start off by clicking the File Tab.

 

Then go to Options.

 

Next click on the Add-Ins tab, then select Templates from the Manage drop-down field.

Click the Attach.. button

 

Find the custom .dotm template you created and click Open. Then close the add-ins menu by clicking OK.

 

We can check the Macros list or press the hotkey to see if we have correctly loaded the template.

NOTE:The macro in the .docx document exists because we attached template, meaning it's not part of the normal.dotm template file, nor is it saved in the document. This makes the adding of similar or identical macros to each document a much easier process. (document automation)

 

Okay, so how is it different from a .docm file?

So we've identified .dotm files, in Microsoft Word, as Template files that contain macros, with the purpose of being applied to .docx files.

.docm files however are a bit different as they are Macro-Enabled Documents (not templates), meaning that all macros that are created in that file type are contained in the document. Let's look at how that works.

Create a new document in Microsoft Word.

Click Record Macro.


Name your macro, and give it a description. (optional)

Click the "Store Macro in" drop-down list and select the current document you are working in. (in this case it is Document1)

CAUTION: Be careful when naming your Macros, as Macro names must begin with a letter and use either letters or numerals. You cannot use spaces, non-alphanumeric characters, or periods. 

Assign a hotkey to the macro.

Next click the "Save Changes in:" drop-down list and select the current document.

Close out the edit menu, and record your Macro.

Test the Macro.

Go to the File Tab, and click Save As and browse where you want to save your file.

NOTE: Note that we tried to save the document as a .docx file while it has macros stored inside of the document. Word gave us a warning that because this file contains a macro, it needs to be saved as a Macro-enabled document (or a .docm file).

Click "No" on the dialogue box. This will bring back the Save As window.

Select a Location where you want to save the file, and select .docm as the file type.

NOTE: Keep in mind that if the macro-enabled document is saved to an un-trusted location, the macros will not run If you try to open the file from that same location.

Test out the macros in your new Macro-Enabled file.