How to Extract and Import Macros from a Word DOCM or DOTM Template
Question details
The user needs to reuse existing VBA code by extracting it from a macro-enabled Word template (.docm or .dotm) and importing it into a new template.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Creating a new template with a different design but needing the same VBA functionalities as an older template.
- Observed behavior
- Transferring VBA macros between files so the new template operates with the established macro code.
Ensure that the original template's VBA project is not password-protected or locked, as locked projects will prevent you from viewing or exporting the macro modules.
Export and Import Macros using the Visual Basic Editor
The most precise way to transfer specific VBA modules from one template to another.
By utilizing the Visual Basic Editor, you can export specific modules from your old template as standalone files and import them directly into the VBA project of your new template.
Open the original macro-enabled template in Word and press Alt + F11 to open the Visual Basic Editor.
In the Project Explorer pane, expand the VBA project for your original template, right-click the desired module, and select 'Export File...' to save it to your computer.
Leave the editor, open your newly designed template in Word, and press Alt + F11 again.
Select the new template's VBA project in the Project Explorer, right-click it, choose 'Import File...', and select the module file you just exported.

Load Macros Globally via the Word Startup Folder
Instead of copying code, you can load the original template as a global add-in so its macros are available to all documents.
Duplicate the Template Using Save As
A straightforward approach if you want to keep all macros and simply alter the document's design.
Manage Word Macros and Templates Easily with WPS Office
WPS Writer offers excellent compatibility with Microsoft Word macro-enabled files (.docm, .dotm). You can easily open, edit, and manage your VBA macros directly within the familiar WPS interface.
- 1. Open Template: Launch WPS Writer and open your .docm or .dotm template file.
- 2. Access Developer Tab: Navigate to the 'Developer' tab on the top ribbon.
- 3. Open Visual Basic Editor: Click the 'Visual Basic Editor' icon to view, export, or import your VBA modules.
- 4. Save Customizations: Adjust the document formatting and go to 'Menu' > 'Save As' to save it as a new macro-enabled template.

Frequently Asked Questions
Why can't I export the macro from my Word template?
If the export option is unavailable or the project won't expand, the VBA project is likely locked or password-protected. You need the original password to unlock the project in the Visual Basic Editor before extracting the code.
What is the difference between .docm and .dotm files?
A .docm file is a macro-enabled Word document used for standard editing, while a .dotm file is a macro-enabled Word template. Templates (.dotm) are used as foundational starting points to generate multiple new documents that inherit the same macros and base formatting.
Where do I find the Developer tab to access the Visual Basic Editor?
If the Developer tab is hidden, go to 'File' > 'Options' > 'Customize Ribbon'. In the right-hand column, check the box next to 'Developer' and click OK to make it visible on your main toolbar.
Can I use my extracted macros in older versions of Word?
Yes, VBA code is generally backwards-compatible. However, if your macro script utilizes specific properties, objects, or features introduced only in newer versions of Word, those specific lines of code may cause errors in older software versions.




