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

Repeating Your Typing

Want a quick way to repeat a word or phrase you just typed? Here's the shortcut you need.

Discover More

Understanding the VLOOKUP Function

Functions are at the heart of Excel's power in working with data. One of the most misunderstood functions provided by ...

Discover More

Fast AutoFill

Want to fill a long column with predictive data? It's easy to do by using AutoFill and a double-click of the mouse.

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Converting Numbers to Text

Got some numbers you need spelled out? Here's a handy macro that can convert numbers like "123" to words like "one ...

Discover More

Toggling Font Assignments in a Macro

If you need to quickly switch a text selection from one typeface to another, one way you can do it is with a macro. This ...

Discover More

Determining How Many Styles are Available

Got a macro that processes or uses styles? You definitely need to know how many styles Word has available in the ...

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 four minus 0?

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.