How to Run a Word Macro When Creating a New Template Document
Question details
The user needs a macro to execute automatically when generating a new DOCX document from a macro-enabled template.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Creating a new document based on a custom DOTM template that contains automated macro tasks.
- Observed behavior
- The macro named AutoOpen does not trigger when a new document is created because it is only designed to run when the template file itself is opened.
Ensure that your template is saved in a macro-enabled format (.dotm) and that your Trust Center settings allow macros to run.
Change the Macro Name to AutoNew
Renaming your macro to AutoNew ensures it triggers specifically when a new document is generated from the template, rather than when the template itself is edited.
In Microsoft Word, automatic macros rely on specific naming conventions to determine when they run. The AutoOpen macro executes only when an existing document or template is opened. When you create a new document from a template, Word considers it a 'New' action, requiring the AutoNew macro instead.
Launch Word and use the File > Open menu to open your .dotm template file directly, rather than double-clicking it to create a new document.
Press the Alt + F11 keys on your keyboard to open the Visual Basic for Applications (VBA) Editor.
In the Project Explorer pane on the left, locate the module containing your code. Find the 'Sub AutoOpen()' line and change it to 'Sub AutoNew()'.
Save the changes to your template (Ctrl + S) and close the VBA Editor. Go to File > New, select your template, and create a new document to verify that the macro runs automatically.

Create and Manage Macro-Enabled Templates in WPS Writer
WPS Office provides robust support for VBA macros and fully integrates with Microsoft Word formats, including .dotm and .docx. You can easily manage AutoNew macros to automate document creation efficiently.
- 1. Enable Developer Tools: Open WPS Writer, go to the Options menu, and ensure the Developer tab is enabled to access macro features.
- 2. Write the AutoNew Macro: Click the Developer tab, select VBA Editor, and enter your 'Sub AutoNew()' code into the template's code module.
- 3. Save as a Macro-Enabled Template: Click Save As, and choose either the WPS Template (.wpt) or Microsoft Word Macro-Enabled Template (.dotm) format.
- 4. Generate New Documents: Create a new document using your saved template; WPS Writer will automatically execute the AutoNew macro without requiring manual triggers.

Frequently Asked Questions
Why does my AutoOpen macro work when editing the template but not when creating a new file?
The AutoOpen macro is specifically designed to trigger only when an existing file is opened. Creating a new file from a template doesn't count as 'opening' the template itself, so the macro is skipped. You must use AutoNew for document creation scenarios.
Can I have both AutoOpen and AutoNew in the same template?
Yes, you can include both macros in your template module. AutoOpen will run when you or another user edits the template directly, and AutoNew will run when users generate new documents from it.
How do I ensure macros run automatically without security warnings?
To prevent security prompts from blocking your macros, you need to add the folder containing your template to the Trusted Locations in your Trust Center settings. Always ensure the template comes from a reliable source before bypassing these warnings.




