Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. 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: Assigning a Macro to a Button in Your Text.

Assigning a Macro to a Button in Your Text

Written by Allen Wyatt (last updated October 5, 2024)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021


You may already know that you can only assign a macro to a button (a tool) on the Quick Access Toolbar. Word also allows you to add buttons within the text of you document. These buttons have a macro or a Word command assigned to them, and you can control what happens when the button is selected in text. This is all instituted through the use of a field code.

It may be a bit of a misnomer to refer to the result of this field code as a "button," because no graphics are involved whatsoever, although you can create your own graphic and embed it into the field. The syntax for the field code is:

MacroButton MacroName Display

MacroName is the name of the macro or command you want to run, and Display is the text you want displayed by the field code. If you use a graphic instead of text, then the graphic is displayed. When a user double-clicks on the displayed text or graphic, then the macro or command defined by MacroName is executed.

To assign a command or macro to a button, and insert that button in your text, follow these steps:

  1. Figure out the name of the macro or Word command you want to use with the button. To find the correct macro or command names you can right click on a blank area of the ribbon then click on Customize (Word 2007) or Customize Quick Access Toolbar (Word 2010 and later). You can find the names in the dialog box.
  2. Position the insertion point where you want the button to appear.
  3. Press Ctrl+F9 to insert a pair of field brackets.
  4. Between the field brackets, type the fieldname MacroButton followed by a space.
  5. Type the name of the command or macro you want the button to execute, followed by a space. (This is the name you determined in step 1.)
  6. Type the button name text you want displayed, or insert a graphic to be used as a button.
  7. Press F9 to update the field display.

The MacroButton field has been around since the earliest days of Word, but in the latest versions of the program, it no longer seems to want to work with a graphic (step 6). If you can get it to work properly with a graphic, I would love to hear about it in the comments.

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 (8658) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Word here: Assigning a Macro to a Button in Your Text.

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

Understanding Background Printing

We click the button to print our document and seldom think of what is happening behind the scenes. Word prints documents, ...

Discover More

Using the MROUND Worksheet Function

If you want to round a value to some multiple of a whole number, you'll want to become familiar with the MROUND function. ...

Discover More

Displaying the Print Dialog Box in a Macro

Want to print a document by using a macro? One way is to display the Print dialog box and allow the user to interact with ...

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)

Displaying Blanks when Summing to Zero

If you use fields to sum the information in your table columns, you might want to display a blank when the sum is zero. ...

Discover More

Inserting Page Number Cross-References

Want to insert a dynamic cross-reference to a particular page number? It's easy to do following the steps in this tip.

Discover More

Inserting the Date Your Document was Last Saved

Word keeps track of the date each time you save your document. If you want to insert that "save date" in your document, ...

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 + 2?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.