Applying the same formatting, styles, and layout to many Word documents one by one is time-consuming and error-prone. Word does not have a built-in batch template tool, but you can use the Organizer and a simple macro to apply a template to multiple files at once. This article explains how to set up your template, attach it to multiple documents using the Organizer, and automate the process with a VBA macro for maximum efficiency.
Key Takeaways: Applying a Template to Multiple Word Files
- Developer > Visual Basic > Insert Module > Paste macro code > Run: Automates attaching a template to all .docx files in a folder.
- Developer > Document Template > Organizer > Copy styles: Manually transfer styles from the template to one document at a time.
- File > Options > Add-ins > Manage Templates: Verify that the template is attached and styles are available after the operation.
What the Template Attachment Feature Does
Every Word document has an attached template, usually Normal.dotm, that provides default styles, AutoText entries, and macros. When you create a custom template with specific styles, headers, footers, and page setup, you can attach it to existing documents to apply those design elements. The template itself is not merged into the document. Instead, the document references the template file, and styles from the template become available for use.
Before you start, prepare your template file. Save it as a .dotm file (macro-enabled) if it contains macros, or as a .dotx file if it only has styles and formatting. Place the template in a folder you can easily locate, such as the default Templates folder at %appdata%\Microsoft\Templates. Ensure the template contains all the styles, page layouts, and formatting you want to apply to the target documents.
The process of attaching a template to a document does not automatically update the document content. After attaching, you must manually apply the styles from the template to each document section, or use the Organizer to copy styles into the document permanently. The macro method below handles both attaching the template and copying styles in one step.
Steps to Apply a Template to Multiple Documents Using a Macro
The most efficient way to apply a template to many documents is with a VBA macro. This method works on all .docx files in a single folder. It attaches the specified template and then copies all styles from the template into each document.
- Enable the Developer tab
Open Word. Go to File > Options > Customize Ribbon. In the right panel, check Developer and click OK. The Developer tab now appears in the ribbon. - Open the Visual Basic Editor
On the Developer tab, click Visual Basic. This opens the VBA editor. If you have never used VBA, the editor shows a blank project pane on the left. - Insert a new module
In the VBA editor, click Insert > Module. A new module window appears. This is where you paste the macro code. - Paste the macro code
Copy and paste the following code into the module window:
Sub ApplyTemplateToMultipleDocuments()
Dim strFolder As String
Dim strFile As String
Dim strTemplate As String
Dim doc As Document' Set the folder containing your documents
strFolder = "C:\YourFolder\" ' Change this path
' Set the full path to your template
strTemplate = "C:\YourFolder\YourTemplate.dotm" ' Change this pathstrFile = Dir(strFolder & "docx")
Application.ScreenUpdating = False
Do While strFile <> ""
Set doc = Documents.Open(strFolder & strFile)
' Attach the template
doc.AttachedTemplate = strTemplate
' Copy styles from template into document
doc.UpdateStyles
doc.Save
doc.Close
strFile = Dir
LoopApplication.ScreenUpdating = True
MsgBox "Template applied to all documents in the folder."
End Sub
Modify the two path variables: strFolder must point to the folder with your .docx files, and strTemplate must point to your .dotm or .dotx file. Use double backslashes in the path. - Run the macro
Press F5 or click the Run button (green triangle) in the VBA toolbar. Word opens each document in the folder, attaches the template, updates styles, saves, and closes the file. A message box appears when all documents are processed. - Verify the result
Open any processed document. Go to Developer > Document Template. The Attached Template field should show the path to your custom template. On the Home tab, the Styles gallery should display the styles from your template.
Common Issues and Limitations
Macro does not run because security settings block it
By default, Word disables macros from unknown sources. To run your own macro, save the document that contains the macro as a .docm file or run the macro from the VBA editor directly. You can also go to File > Options > Trust Center > Trust Center Settings > Macro Settings and select Enable all macros. Revert this setting after you finish to maintain security.
Styles are not applied to existing content
The macro uses doc.UpdateStyles, which adds styles from the template to the document but does not automatically reformat existing text. To apply a specific style to text, you need to select the text and choose the style from the Styles gallery. For consistent formatting, design your template styles with the same names as the styles already used in the documents. Word will then update the formatting of existing text that uses those style names.
Macro skips some documents or fails silently
The macro processes only .docx files in the root of the specified folder. It does not search subfolders. If a file is open in another program, the macro will skip it. Ensure all target files are closed and located directly in the folder you specify in strFolder.
Template contains macros that need to run
If your template includes macros that must execute when the document opens, use a .dotm file. After attaching the template, the macros become available in the document. To run them automatically, you need to place the macro code in the document’s ThisDocument module or use an AutoOpen macro stored in the template. The macro above does not trigger template macros; it only attaches the template and copies styles.
Manual Method vs Macro: Time and Control Comparison
| Item | Manual Organizer Method | VBA Macro Method |
|---|---|---|
| Number of steps per document | 5-7 steps | 1 macro run for all files |
| Ability to choose individual styles | Yes, you pick which styles to copy | Copies all styles from the template |
| Requires VBA knowledge | No | Yes, to edit paths and run the code |
| Risk of error | Higher with many files | Low if paths are correct |
| Best use case | One or two documents with selective styles | Ten or more documents needing full style update |
The manual method uses the Organizer: open a document, go to Developer > Document Template > Organizer, click the Styles tab, click Close File on the right side, then Open File to select your template, and copy individual styles to the document. This gives you fine control but is impractical for batches larger than a few files. The macro automates the entire batch but applies all styles without selection.
You can now apply your custom template to an entire folder of Word documents in seconds using the VBA macro. Start by testing the macro on a backup copy of your files. After you confirm the styles transfer correctly, run it on your working documents. For more advanced automation, modify the macro to also update headers, footers, or page setup by adding lines that set doc.PageSetup properties or doc.Sections(1).Headers objects.