Understanding DOCX vs DOCM: How to Save Macros in Microsoft Word
Question details
The user needs to understand the difference between DOCX and DOCM formats, specifically regarding how Microsoft Word stores and executes VBA macros.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Saving a Word document that contains VBA macros without losing the macro code.
- Observed behavior
- When saving a macro in a DOCX file, Word displays a warning and removes the macro code. Macros must be saved in a DOCM file to be retained, though DOCX files can still run macros stored in global templates.
Before saving your document, determine whether it requires embedded VBA macros to function or if it will rely on personal macros stored locally in your global templates.
Save the Document as a Macro-Enabled Format (DOCM)
Use the DOCM format when you need to embed and retain VBA code directly within your Word document so it can be shared with others.
While you can record or write a macro while working in a standard DOCX file, Microsoft Word will not allow you to save the macro in that format. You must choose the macro-enabled format to prevent losing your code upon saving.
Click on 'File' in the top-left corner of Microsoft Word and select 'Save As' to choose your desired destination folder.
In the 'Save as type' dropdown menu, scroll through the list and select 'Word Macro-Enabled Document (*.docm)'.
Click the 'Save' button. Your document will now retain both its textual content and the embedded VBA macros.

Use Global Templates to Run Macros in a DOCX File
If you must use the standard DOCX format, you can still execute macros by storing them in a global template rather than the document itself.
Open and Save DOCX and DOCM Files in WPS Office
WPS Office provides excellent compatibility with Microsoft Word formats. You can effortlessly open, edit, and save standard DOCX documents, as well as handle macro-enabled formats using WPS Writer.
- 1. Download WPS Office: Download and install the free WPS Office suite on your computer.
- 2. Open your file: Launch WPS Writer, click on 'Menu', select 'Open', and choose your DOCX or DOCM file.
- 3. Edit and save: Make the necessary edits to your document. Click 'Menu' > 'Save As' and select 'Word Macro-Enabled Document (*.docm)' if you need to retain VBA macros.

Frequently Asked Questions
Why did my macros disappear after saving a DOCX file?
DOCX files are deliberately designed without the ability to store executable code for security reasons. If you save a document containing macros as a DOCX, Word automatically strips the VBA code to keep the file safe. To retain your code, you must save the file as a DOCM.
What is the difference between DOTX and DOTM?
DOTX is a standard Microsoft Word template format, while DOTM is a macro-enabled template. Just like the relationship between DOCX and DOCM, you must use DOTM if you want your template to store VBA macros.
How do I run a macro in a DOCX file if it cannot be saved?
While the DOCX file itself cannot store the macro code, it can execute macros that are saved in your computer's global template (Normal.dotm) or another attached template while the document remains open.
Can a standard DOCX file contain a macro virus?
Because DOCX files are technically incapable of storing VBA macros, they carry a significantly lower risk of containing macro-based viruses. This strict separation is the primary reason Microsoft introduced the independent DOCM format.




