Fix a Word AutoExec Macro That Does Not Run in a DOCM File
Question details
Run a macro automatically when a Word document opens or when a new document is created from a template.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A macro is stored in a macro-enabled Word document and should run automatically.
- Observed behavior
- The AutoExec macro does not run when the DOCM file opens.
Confirm whether you want the macro to run when an existing DOCM opens or when a new document is created from a template. Only enable macros or trust locations for files from sources you trust.
Use AutoOpen to run the macro when the DOCM opens
Use AutoOpen when the macro should run each time the existing document is opened.
AutoExec is intended for Word startup and global templates, rather than opening an individual DOCM file.
Open the DOCM file in Word, then select Developer > Visual Basic. If the Developer tab is hidden, enable it under File > Options > Customize Ribbon.
In the VBA editor's Project pane, open the standard module containing the macro and rename the procedure from AutoExec to AutoOpen. The procedure should take no arguments.
Select File > Save in Word, close the document, and reopen the DOCM file. If prompted, enable macros only if you trust the file.
If the macro still does not run, open File > Options > Trust Center > Trust Center Settings and review Macro Settings. You can also review Trusted Locations and use a trusted location for a file you trust.
Use AutoNew in a DOTM template for new documents
Use AutoNew when the macro should run as a new document is created from a template.
Edit Word Documents with WPS Office
WPS Office is a free, lightweight alternative for everyday document editing, with a familiar interface and support for common Microsoft Word formats. Open existing files to make migration easier; it does not fix Microsoft Word's AutoExec behavior.

Frequently Asked Questions
Why does AutoExec work in Normal but not in my DOCM file?
AutoExec is designed for Word startup and global templates, such as Normal, rather than for opening an individual document. Use AutoOpen in the DOCM file when the macro should run as that document opens.
When should I use AutoNew instead of AutoOpen?
Use AutoNew in a macro-enabled DOTM template when the macro should run as a new document is created from that template. Use AutoOpen when an existing document is opened.
Where can I check whether Word allows macros?
In Word, go to File > Options > Trust Center > Trust Center Settings > Macro Settings. Only enable macros for files you trust; your organization may control these settings.
Will opening a DOTM template run AutoNew?
AutoNew is intended to run when you create a new document from the template, not merely when you open the template for editing. Use File > New and select the template to test it.




