Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Automatically Running a Macro.

Automatically Running a Macro

Written by Allen Wyatt (last updated June 1, 2021)
This tip applies to Word 2007, 2010, 2013, and 2016


3

You know that you can create macros within Word that allow you to automate many different functions. You may not know, however, that you can create macros that perform tasks without any intervention on your part. For instance, you can create a macro that Word will run automatically whenever you create a document; whenever you use the New command, this macro will run.

These special macros that automatically run at predefined times are identified by special names. Otherwise, there is nothing different between these macros and any other you may write. Here are the names you can give macros so that they will run automatically.

Macro Name When It Runs
AutoNew Whenever you create a new document
AutoClose Whenever you close a document
AutoExec Whenever you start Word
AutoExit Whenever you exit the program
AutoOpen Whenever you open a document

Remember that these macros, in order to be used effectively, must be saved within a DOCM document. (That is, within a document that is "macro enabled.") They cannot be saved in a DOCX document, as such documents cannot contain macros at all.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (9388) applies to Microsoft Word 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Word here: Automatically Running a Macro.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Connecting To a Discussion Server

How to connect to a discussion server for online collaboration.

Discover More

Restarting a Numbered List Easily

Word provides tools that allow you to add numbered lists to your documents. Sometimes the quirks built into these tools ...

Discover More

Disappearing Column Formatting

Two things go into making your documents look just right: content and formatting. If the formatting seems to disappear on ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Removing Shortcuts for Macros

Word apparently has a bug in it that makes it very difficult to remove a shortcut key previously associated with a macro. ...

Discover More

Understanding Precedence

Formulas created in a macro have a specific order in which operations are performed. This is known as precedence, as ...

Discover More

Reducing the Size of Spaces in a Selection

If you want to decrease the size of spaces in some selected text, the best approach is to use a macro. This tip includes ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 8?

2022-12-19 13:19:30

tim mc

Here's a tricky one. I would like to create a macro that executes after a file is selected in the File>Open dialog but before MS Word has actually opened/locked the document (want to shell out and run an app to an external version control commend on the file - a Get Latest type operation).

I believe the autoopen event would be too late for this. I want to avoid a kluge of creating a file flag, dynamically creating a batch file, closing word and chaining to new instance of word once the version control operation has been completed.


2018-10-18 01:54:18

Ken Gosse

I just want to thank you for many or your tips that I've used over a number of years to customize Word for my needs at home. My projects are not collaborative, so I don't worry about customizations to the default template (which I've learned to save as a copy in the default template folder as well as in my code document folders in a locations not affected by Windows or Office updates). Today, your page "Displaying the Navigation Pane when Opening a Document" showed me [CommandBars("Navigation").Visible]. I usually leave the Navigation panel open and know that ctrl-F will open it, too. I was looking for a way to automatically adjust the size when I open a document. Using your code, I discovered that [.Width] lets me do that, and I tested various widths to find what works best. Then I found your "Automatically Running a Macro" and added an AutoExec sub to adjust the panel width whenever I open a Word doc. (I do all my work in DOCM and, as necessary, save as a DOCX, such as when I submit poetry to online sites). Since I often need to review the sources of my code, I (almost) always include a comment with the web link for tips such as yours.
By the way, some of your tips port directly into my Access database codes, others send me in the right direction for Access. My Access macros inlcude thousands of lines of code. Site like yours offer invaluable help. I'm already subscribed to your newsletter, too.


2017-09-20 14:07:47

Bob Mathews

Surely there's something about this that I'm totally missing. The way I read the article, these 5 macros are macros I can create, and assign one of the 5 names to it, depending on when I want it to run. My Normal.dotm already has an AutoExec though, and it's locked. What's up?


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.