logo
search
VBA & Macro Problems

How to Run a VBA Macro Automatically When a Publisher Document Opens

Elise WilliamsElise Williams Oct 1, 2026 869 views

Question details

The user wants to trigger a VBA macro to run automatically upon opening a Microsoft Publisher document.

How to Run a VBA Macro Automatically When a Publisher Document Opens
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 you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Launch Microsoft Publisher, open your document, and press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor.

2
Access the Document Module

In the Project Explorer pane on the left side, locate your Publisher project and double-click on 'ThisDocument'.

3
Select the Open Event

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.

4
Insert Your Macro Code

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.

Use Document_Open Event Handling
Global Template Considerations: If you are trying to run the macro globally for all Publisher documents, you will need to create a Class Module to capture Application-level events, which requires more advanced VBA configuration.
Free Microsoft Office alternative

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. 1. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
  2. 2. Install WPS Office: Run the downloaded setup file and follow the on-screen instructions to complete the installation.
  3. 3. Enable VBA Features: Open WPS Writer or Spreadsheets, navigate to the Developer tab, and start recording or writing your macros seamlessly.
Fully compatible with Microsoft Office formats including .docm, .xlsm, and .pptm macro files.Built-in VBA editor makes it easy to write, edit, and run macros directly in Writer and Spreadsheets.Lightweight design ensures fast loading times, even on older computers.Free to use with a clean, familiar tabbed interface.
microsoft office alternative - wps office

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.