Creating Macros That Run Automatically

In most cases, you should give your macro a name that describes its function so that you can easily remember its purpose later. There are, however, several special names you can give your macros. These names cause your macros to run automatically when certain events occur in Word:

  • A macro named AutoExec runs when you start Word. For this macro to work, you need to store it in your template or another global template.


    The capitalization used in this discussion isn't required; autoexec and Autoexec will work the same way as AutoExec. You cannot, however, give this function a completely new name.

  • A macro named AutoExit runs when you exit Word. If you want a macro to run every time you exit Word, store this macro in or another global template.

  • A macro named AutoNew runs when you create a new document. If you save this macro in a specific template, such as a memo template, then the macro runs each time you create a new document based on that template.

  • A macro named AutoClose runs when you close a document. If you save this macro in a specific template, it runs when you attempt to close the template or any document based on the template.

  • A macro named AutoOpen runs when you open the template that contains it or any document based on the template.


The names AutoNew, AutoClose, and AutoOpen are included for compatibility with earlier versions of Word, but similar functionality is provided by the VBA event procedures DocumentNew, DocumentClose, and DocumentOpen.

Unlike AutoNew and the other "automatic" macro names, these VBA event procedures are not the names of macros, but rather the names of VBA commands that can be included in those macros. If you're not comfortable writing VBA code, use the automatic macro names instead.

    Part I: Word Basics: Get Productive Fast
    Part II: Building Slicker Documents Faster
    Part III: The Visual Word: Making Documents Look Great
    Part IV: Industrial-Strength Document Production Techniques
    Part VI: The Corporate Word