To create a Word template that contains a macro, start with a blank document or an existing file, record or add the task you want to automate, then save the file as a Word Macro-Enabled Template (.dotm). Open the template in Word for Microsoft 365 on Windows, use the Developer tab to record a macro, and save the template. The .dotm format is essential: a regular .dotx template cannot store VBA macros.
What You’ll Need
- Microsoft Word for Microsoft 365 desktop on Windows. Word for the web can open documents, but it cannot create, run, or edit VBA macros.
- A blank document or a document whose layout you want to reuse, such as a letterhead, report, or form.
- A clear idea of the repeatable steps you want the macro to perform. If you plan to record it, practice the steps first.
- A safe location for the template. If Word blocks its macros, you may need to use a Trusted Location approved for your device.
Step-by-Step
- Plan the template and the macro. Decide what should be built into every document and what the macro should do when someone runs it. A template might contain a logo, page margins, heading styles, and standard footer text; a macro could apply a set of formatting choices or insert a prepared block of text. Keep the macro’s job narrow and repeatable. A recorded macro captures actions, so unnecessary clicks or corrections during recording can become part of its behavior.
- Create or open the starting document. In Word, choose File > New > Blank document, or open an existing document to use as your starting point. Add the content and formatting that should appear in documents created from the template. For example, set the page layout, add recurring headings, and create styles rather than manually formatting each heading. Avoid putting example text in places where users might mistake it for content they should keep.
- Save a macro-enabled template before recording. Choose File > Save As > Browse. In the Save as type list, select Word Macro-Enabled Template (*.dotm), give the file a clear name, and save it in a location you can find again. Saving first helps ensure the macro is stored with the template rather than in a separate document or in Word’s global Normal template. If Word shows a format warning, confirm that you want to keep the macro-enabled format.
- Show the Developer tab if it is hidden. Choose File > Options > Customize Ribbon. In the Main Tabs list on the right, check Developer, then select OK. The Developer tab should now appear on the ribbon. This is where Word provides the macro recorder, macro list, and Visual Basic tools. You only need to turn the tab on once for your Word profile.
- Start recording and choose where to store the macro. Open the template you just saved if it is not already open, then choose Developer > Record Macro. Enter a descriptive name, such as ApplyStandardHeading. Macro names cannot contain spaces; begin with a letter and use letters, numbers, or underscores. In the Store macro in list, choose the name of your open template, not All Documents (Normal.dotm), if the macro should travel with this template. Optionally assign the macro to a button or keyboard shortcut in the dialog. Choose OK to begin recording.
- Perform only the actions the macro should repeat. Carry out the task in Word using the ribbon or keyboard. For example, to record consistent formatting, select a sample heading and apply the intended style and formatting. Avoid pauses, exploratory clicks, and edits that are not part of the planned task. Word records many interface actions, but it does not understand your intent; selecting the wrong text while recording can make the macro behave incorrectly later.
- Stop recording and check the result. When the actions are complete, choose Developer > Stop Recording. If the Developer tab is not visible, look for the stop control on the status bar or use the recording controls available in your Word version. Save the template with Ctrl+S. On a Mac, use Command+S. Close the template and, if Word asks whether to save changes to the template, choose to save them.
- Test the template in a new document. Create a fresh document from the template rather than testing only in the template file. On Windows, choose File > New and look for the Personal or Custom templates area; its label can vary by setup. If the template does not appear, open the .dotm file directly to create a document from it. Run the macro using Developer > Macros, select its name, and choose Run, or use the button or shortcut you assigned. Check that it changes only the intended content, then close the test document without saving if you do not need it.
- Make the template easy to find and maintain. Keep the master .dotm in a stable folder and make a backup before making significant changes. On Windows, you can set the personal templates folder through File > Options > Save > Default personal templates location. Put the template there if you want it listed in Word’s personal templates area. If colleagues need the template, provide the .dotm file through an approved shared location and explain that they may need to trust its source before macros will run.
Common Mistakes
Saving as .dotx or .docx: These formats do not preserve VBA macros. If Word warns that features cannot be saved in the selected format, go back to Save As and select Word Macro-Enabled Template (*.dotm). A macro-enabled document uses .docm; a reusable macro-enabled template uses .dotm.
Storing the macro in Normal.dotm by accident: Normal.dotm is Word’s global template, and macros saved there are not automatically included when you share a different template. Check the Store macro in choice before recording. If the macro has already been saved in the wrong place, record or copy it into the intended template and test that copy.
Recording the wrong selection or extra actions: The recorder can capture a particular selection, cursor position, or formatting action. A macro that worked once may then affect the wrong paragraph in another document. Test it on a fresh document with different sample text and re-record the task more carefully if needed.
Expecting macros to run in Word for the web: The web app does not run VBA. Open the file in the Word desktop app for Windows or Mac. Also, never enable all macros just to make one template work; use only files from sources you trust and follow your organization’s security policy.
Tips
- Use names that describe an action, such as InsertContactBlock or FormatReportTitle, so users can recognize the macro in the list.
- Build reusable formatting into named Word styles whenever possible. A macro that applies a style is often easier to maintain than one that repeats several individual font and paragraph settings.
- Keep recorded macros focused. If you need a complex workflow with decisions, repeated steps, or prompts, the recorder may not be sufficient; a VBA developer can create and review a more suitable macro.
- Document what the macro changes and how to run it. If you assign a ribbon button or keyboard shortcut, include that instruction with the template so other users are not left guessing.
- Protect the original master by keeping a backup. A macro can make many changes quickly, and Word’s ordinary Undo behavior is not a dependable way to reverse every macro operation.
- On Mac, the same .dotm file format is used, but ribbon labels and template-location settings may differ. Word for Mac includes macro tools in its desktop app; use the Developer tab if available and check Word > Settings or Preferences for template and security options.
Troubleshooting
The macro does not appear in the Macros list: Confirm that the template is open and that you selected it in the Store macro in list when recording. Reopen the .dotm file in desktop Word, then choose Developer > Macros. If the macro is listed under a different open document or Normal.dotm, it was stored somewhere else; save or recreate it in the correct template.
Word says macros are disabled: Close the file and verify that it came from a source you trust. Windows may mark files downloaded from the internet as blocked. If the file is trusted and your organization permits it, ask your administrator about the approved way to unblock it or store it in a Trusted Location. For personal settings, the path is File > Options > Trust Center > Trust Center Settings > Trusted Locations. Do not lower macro protections globally or enable every macro to bypass a warning.
The template is missing from File > New: The file may be saved outside Word’s personal templates folder, or the folder location may not be configured. Open it directly using File > Open > Browse to confirm it works, then check File > Options > Save for the default personal templates location. The exact names shown under File > New can vary by Word build and organization settings.
The macro runs but affects the wrong text: A recorded action may depend on the insertion point, selection, or document structure that existed during recording. Test with a clean document and inspect each action in the sequence. Re-record using stable actions, such as applying a named style to a clearly selected paragraph. For code-based macros, have a qualified VBA developer review the logic before using it on important files.
Changes to the template are not being saved: Make sure you opened the .dotm master itself when editing it; opening a template normally creates a new document based on it. Save changes while the template is open and respond to any prompt about saving the template. If you only changed a document created from the template, those changes do not automatically update the master.
Frequently Asked Questions
What is the difference between .dotm and .docm?
A .dotm file is a Word template that can store macros and be used to create documents. A .docm file is a macro-enabled document, typically used for one specific piece of work rather than as a reusable template.
Can I create a macro in Word for the web?
No. Word for the web does not create or run VBA macros. Use the Word desktop application on Windows or Mac to record, edit, or run a macro-enabled template.
Will the macro work for someone else who receives my template?
The macro is included if it is stored in the .dotm file, but the recipient’s Word security settings may block it. Share templates only through trusted, approved channels, and give recipients instructions to follow their organization’s macro policy.
Can I add a macro to an existing Word template?
Yes. Open the existing .dotm template itself in desktop Word, record the macro with that template selected as its storage location, and save. If the existing template is .dotx, use Save As to create a .dotm copy before adding a macro.
Can I edit a recorded macro after making it?
Yes. In desktop Word, choose Developer > Macros, select the macro, and choose Edit to open the VBA editor. Make changes only if you understand the code, keep a backup copy, and test the edited macro on a disposable document first.
Can I use the same template on Mac and Windows?
Generally, a .dotm template can be opened in Word desktop on both platforms, but ribbon locations, security prompts, and some macro behavior can vary. Test the template on each platform your users rely on, and do not assume it will run in Word for the web.
Related
- How to Compress Pictures in PowerPoint 365
- Compress Photos in PowerPoint to Reduce File Size
- Compress Pictures in PowerPoint: Step-by-Step Guide
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Break Loop: Keyboard Shortcuts and FixesTo interrupt a running Excel VBA loop on Windows, press Ctrl+Break (sometimes labeled Pause/Break); on a Mac, press…
- Macro Recorder for Mac: Record and Run Excel MacrosIn Excel for Mac, turn on the Developer tab, choose Developer > Record Macro, perform the steps you…
- Excel VBA: Find the Last Column With Data in a RowTo find the last column containing data in a particular row, use ws.Cells(rowNumber, ws.Columns.Count).End(xlToLeft).Column. For the last column…
- Excel VBA UserForm: Delete a Record by ID with CodeTo delete a record from an Excel VBA UserForm, identify it by a unique ID, ask the user…
- Excel VBA: Check Whether a Dynamic Array Is AllocatedNo—VBA arrays are not objects, so If myArray Is Nothing is not a valid way to test one.…
- Excel VBA: Find the Last Cell with Data in a ColumnIn Excel VBA, use Cells(Rows.Count, columnNumber).End(xlUp).Row to find the last nonblank cell’s row in a column. Check for…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.