VBA & Macro Problems

How to Extract and Import Macros from a Word DOCM or DOTM Template

Algirdas JasaitisAlgirdas Jasaitis Nov 3, 2026 869 views

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.

How to Extract and Import Macros from Word Templates
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Original Template

Open the original macro-enabled template in Word and press Alt + F11 to open the Visual Basic Editor.

2
Export the Module

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.

3
Open New Template

Leave the editor, open your newly designed template in Word, and press Alt + F11 again.

4
Import the Module

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.

Export and Import Macros using the Visual Basic Editor
VBA Project Lock: This method requires the original VBA project to be unlocked. If it is secured with a password, you must enter the password to unlock it before exporting.

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. 1. Open Template: Launch WPS Writer and open your .docm or .dotm template file.
  2. 2. Access Developer Tab: Navigate to the 'Developer' tab on the top ribbon.
  3. 3. Open Visual Basic Editor: Click the 'Visual Basic Editor' icon to view, export, or import your VBA modules.
  4. 4. Save Customizations: Adjust the document formatting and go to 'Menu' > 'Save As' to save it as a new macro-enabled template.
Fully compatible with Microsoft Word .docm and .dotm filesFamiliar Developer tab and Visual Basic Editor interfaceLightweight, fast, and feature-rich document editorSeamless migration of existing macro-enabled templates
microsoft office alternative - wps office

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.