How to Run a VBA Macro Automatically When a Publisher Document Opens
Question details
The user wants to trigger a VBA macro to run automatically upon opening a Microsoft Publisher document.

- Product
- Microsoft Publisher
- Device & OS
- not provided
- Scenario
- Automating tasks or workflows using VBA scripts as soon as a Publisher file is opened.
- Observed behavior
- Microsoft Publisher does not support the standard Word AutoOpen procedure, requiring alternative application or document event handling to achieve the same result.
Before modifying VBA code, ensure that the Developer tab is enabled in your Publisher ribbon and that your macro security settings are configured to allow macros to run.
Use Document_Open Event Handling
Since Publisher doesn't support the traditional AutoOpen macro used in Word, you must use the Document_Open event built into Publisher's object model.
Microsoft Publisher's VBA architecture relies strictly on document and application-level events. Instead of placing an AutoOpen macro in a standard module, you must place your code inside the ThisDocument module so it listens for the Open event.
Launch Microsoft Publisher, open your document, and press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor.
In the Project Explorer pane on the left side, locate your Publisher project and double-click on 'ThisDocument'.
At the top of the code window, use the left dropdown menu to select 'Document'. Then, use the right dropdown menu to select 'Open'. This will automatically generate a Private Sub Document_Open() procedure.
Paste or type the macro code you want to execute inside the generated Document_Open subroutine. Save the file as a Macro-Enabled Publisher Document.

Consult the Microsoft Office VBA Community
For complex Publisher automation, such as application-wide events or global templates, reaching out to VBA specialists is highly recommended.
Need a Versatile Office Suite with Seamless Macro Support?
If you frequently rely on VBA macros for document automation, WPS Office offers a comprehensive, lightweight suite with excellent macro capabilities. Transition smoothly with full compatibility for your essential document formats, without the recurring subscription costs.
- 1. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
- 2. Install WPS Office: Run the downloaded setup file and follow the on-screen instructions to complete the installation.
- 3. Enable VBA Features: Open WPS Writer or Spreadsheets, navigate to the Developer tab, and start recording or writing your macros seamlessly.

Frequently Asked Questions
Why doesn't the AutoOpen macro work in Microsoft Publisher?
Unlike Microsoft Word, Publisher's VBA object model does not recognize standard AutoOpen macros placed in regular modules. Instead, Publisher relies strictly on specific document and application event handlers, such as Document_Open, to trigger code automatically.
Where should I place the VBA code to run when a Publisher file opens?
You should place your initialization code inside the 'ThisDocument' module of your Publisher VBA project, specifically within the Private Sub Document_Open() procedure.
Can I trigger macros when any Publisher document opens on my computer?
Yes, but it requires setting up application-level events. You must create a Class Module with the WithEvents keyword tied to the Publisher Application object, and then instantiate that class when Publisher starts.




