How to Run a VBA Macro Automatically When Word Opens
🔍 WiseChecker

How to Run a VBA Macro Automatically When Word Opens

You want a VBA macro to start every time you launch Word without manually running it. Word does not have a built-in setting to auto-run a macro on startup, but it supports an event-driven trigger called AutoExec. This article explains how to use the AutoExec macro to automate tasks like applying a custom template, clearing the clipboard, or resetting default formatting when Word starts.

Key Takeaways: How to Trigger a VBA Macro on Word Startup

  • AutoExec macro in Normal.dotm: Place a macro named AutoExec in the Normal.dotm template to run it every time Word opens.
  • Visual Basic Editor (Alt+F11): Open the VBA editor to create and edit the AutoExec macro code.
  • Trust Center > Macro Settings > Enable all macros: Required to allow the AutoExec macro to run without a security prompt.

What Is the AutoExec Macro in Word VBA

The AutoExec macro is a special subroutine that Word runs automatically when the application starts. It must be stored in the Normal.dotm global template. Unlike other macros that run when a document opens (AutoOpen) or closes (AutoClose), AutoExec fires exactly once per Word session, before any document is loaded. This makes it ideal for tasks that affect the entire Word environment, such as setting default fonts, enabling a specific view, or loading an add-in.

To use AutoExec, you need basic VBA knowledge. The macro code is written in the Visual Basic Editor. You must also adjust Word’s macro security settings so the macro is allowed to run. By default, Word disables all macros with notification. The AutoExec macro will not run unless you change this setting to “Enable all macros” or digitally sign the macro project.

Prerequisites for Creating an AutoExec Macro

Before you write the macro, confirm the following:

  • You have access to the Developer tab in Word. If not, enable it by going to File > Options > Customize Ribbon and checking Developer.
  • You understand the VBA code you want to run. Test the macro manually before setting it to auto-run.
  • You are prepared to change macro security settings, which may expose Word to malicious macros if you open untrusted documents.

Steps to Create and Run an AutoExec Macro

Follow these steps to add an AutoExec macro to the Normal.dotm template and configure Word to run it on startup.

Step 1: Open the Visual Basic Editor

  1. Open Word
    Make sure no documents are open that you do not want to modify. The AutoExec macro will be stored in the global template.
  2. Press Alt+F11
    This opens the Visual Basic for Applications editor. You can also click Developer > Visual Basic.

Step 2: Insert the AutoExec Macro in Normal.dotm

  1. Locate Normal.dotm in the Project Explorer
    In the VBA editor, look for the Project pane on the left. Expand “Normal” if it is not already expanded.
  2. Right-click Normal and insert a module
    Right-click Normal, select Insert, then Module. A new code window opens.
  3. Write the AutoExec macro
    In the code window, type the following structure:
    Sub AutoExec()
    ' Your code here
    MsgBox "Word has started"
    End Sub

    Replace the MsgBox line with your actual VBA code. The macro name must be exactly AutoExec (case-sensitive).
  4. Save the macro
    Press Ctrl+S to save the Normal.dotm template. If prompted, confirm saving changes to the global template.

Step 3: Adjust Macro Security to Allow the Macro to Run

  1. Open Trust Center
    Go to File > Options > Trust Center > Trust Center Settings.
  2. Select Macro Settings
    Click Macro Settings in the left pane.
  3. Choose Enable all macros
    Select “Enable all macros (not recommended; potentially dangerous code can run)”.
  4. Check VBA project object model access
    If your macro interacts with the VBA object model, also check “Trust access to the VBA project object model”.
  5. Click OK
    Close all dialog boxes. Restart Word to test the macro.

Step 4: Test the AutoExec Macro

  1. Close Word completely
    Ensure no Word process is running in the background.
  2. Launch Word
    If you used the MsgBox example, a message box should appear immediately after Word opens. If nothing happens, review the macro name and security settings.

Common Issues When AutoExec Does Not Run

AutoExec macro is not in Normal.dotm

The AutoExec macro must reside in the Normal.dotm template. If you placed it in a different template or document, it will not run. Open the VBA editor, confirm the macro is under Normal > Modules, and not under a project named after a specific document.

Macro security blocks execution

If your macro setting is “Disable all macros with notification”, Word will not run the AutoExec macro. Change the setting to “Enable all macros” as described in Step 3. For production environments, consider digitally signing the macro project instead of lowering security.

Word is started from a document shortcut

If Word is launched by double-clicking a document file, the AutoExec macro still runs. However, if the document contains an AutoOpen macro, that macro runs after AutoExec. The order is always AutoExec first, then AutoOpen. If your AutoExec depends on a blank document, it may behave differently when a specific document is opened.

Macro contains errors that prevent execution

A syntax or runtime error in the AutoExec macro will stop it from running. Test the macro manually by pressing F5 in the VBA editor before relying on the auto-run behavior. If an error occurs on startup, Word may show a debug prompt or silently skip the macro.

AutoExec vs AutoOpen: Key Differences

Item AutoExec AutoOpen
Trigger event Word application startup Opening a specific document
Storage location Normal.dotm global template Any document or template
Runs when Once per Word session, before any document loads Each time a document containing the macro is opened
Use case Global environment settings (default font, add-in loading) Document-specific actions (formatting, cleanup)
Security requirement Macros must be enabled globally Macros must be enabled for the document

You can now set up an AutoExec macro to automate any repetitive task when Word starts. For a next step, explore the AutoNew macro which runs when you create a new document from a template. An advanced tip: use the Application.OnTime method inside AutoExec to schedule a macro to run a few seconds after startup, which avoids interfering with Word’s initial loading sequence.