logo
search
VBA & Macro Problems

How Macros Work in Word: DOCX, DOCM, DOTX, and DOTM Files

Maira MehtabMaira Mehtab Sep 21, 2026 869 views

Question details

The user wants to understand the behavior and rules for storing, attaching, and invoking VBA macros across various Word document formats, including DOCX, DOCM, DOTX, and DOTM.

Product
Word
Device & OS
not provided
Scenario
Creating, sharing, and executing VBA macros in Word documents while adhering to format limitations and security policies.
Observed behavior
A standard DOCX file cannot store VBA project code, requiring users to use attached DOTM templates, macro-enabled formats, or Startup-folder add-ins to utilize macros.
Before you start

Ensure that the Developer tab is enabled in your word processor's ribbon, and verify your macro security settings to prevent running unauthorized or potentially dangerous code from untrusted sources.

Solution 1Recommended

Invoke Macros in a DOCX File via a DOTM Template

Because DOCX files cannot store their own VBA code, you can attach a macro-enabled template (DOTM) to access its embedded macros.

A standard DOCX file is strictly macro-free. However, if the DOCX file is based on or manually attached to a macro-enabled DOTM template, it can successfully invoke the macros stored within that parent template.

1
Open your document

Open your macro-free DOCX document in your word processor.

2
Access Document Templates

Navigate to the Developer tab on the ribbon and click on 'Document Template'.

3
Attach the DOTM file

Click the 'Attach' button to browse your computer and link your DOTM file containing the necessary macros.

4
Run the macros

Once attached, you can run the macros from the Macros menu, provided your security settings allow them to execute.

Macro Security Reminder: Always keep macro security enabled to prompt you before running code, especially when attaching files from external or shared network sources.
WPS Office VBA Support

Manage and Run VBA Macros with WPS Office

WPS Office offers comprehensive support for VBA macros in its advanced versions. You can easily open DOCM files, attach DOTM templates, and utilize the built-in Visual Basic Editor to automate your document workflows.

  1. 1. Download WPS Office: Download and install WPS Office, ensuring you opt for a version that includes VBA capabilities.
  2. 2. Open your macro file: Launch WPS Writer and open your DOCX, DOCM, or DOTM file.
  3. 3. Access Developer tools: Navigate to the Developer tab on the top ribbon to open the Visual Basic Editor, manage Document Templates, and run your macros.
Fully compatible with Microsoft Word DOCX, DOCM, and DOTM formatsBuilt-in VBA editor for creating, debugging, and running macrosFamiliar ribbon interface for seamless transition and ease of useLightweight application with fast launch and processing speeds
QA img-9

Frequently Asked Questions

Can a standard DOCX file contain VBA macros?

No, a standard DOCX file is designed to be macro-free and cannot store VBA project code. If you attempt to save a document containing macros as a DOCX, the macro code will be stripped. To embed macros directly within the file, you must save it as a Macro-Enabled Document (DOCM).

Why aren't macros from Normal.dotm available in all my documents?

Macros stored in Normal.dotm typically apply only to documents that are explicitly created based on that specific template. To make macros universally available across all open files, consider placing a macro-enabled template inside the application's Startup folder, which loads it as a global add-in.

Are DOCM and DOTM files safe to open?

Because DOCM and DOTM files can contain executable VBA code, they inherently carry a security risk if they are obtained from untrusted sources. You should always keep your macro security settings set to prompt you before executing any code, ensuring you only run macros from verified and trusted authors.