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: Assigning a Macro to a Button in Your Text.

Assigning a Macro to a Button in Your Text

Written by Allen Wyatt (last updated August 12, 2017)
This tip applies to Word 2007, 2010, 2013, and 2016


4

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.

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, and 2016. 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

Viewing More than Two Places in a Worksheet

If your worksheet gets big enough, it is easy to spend a lot of time navigating back and forth between different areas. ...

Discover More

Avoiding the Update Links Message

Word allows you to establish links from one document to another. When you open a document containing these links, you may ...

Discover More

Converting Individual Endnotes and Footnotes

Word makes it easy to convert all your footnotes to endnotes and vice versa. You may want to only convert a couple of ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Using TC Fields for Notes

The TC field is normally used in constructing manual Tables of Contents. The way the field works, however, makes it a ...

Discover More

Field Calculations in Locked Forms

When adding form fields to a document, you may want some of the fields to be automatically calculated from other fields. ...

Discover More

Indicating the Date Changes were Last Made

Do you want to keep track of when changes were made to your document? This tip looks at a couple of ways to do it, along ...

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?

2019-08-05 08:27:44

Nhat Minh Nguyen

Hi Mr. Wyatt,

Thank you for sharing this wonderful trick. I have a question relating to this. I use this method to assign the 'Back button' macro to a button in Word. It worked perfectly. However, when I convert the document into the PDF file, I could not perform the same like in the word (other hyperlinks work normally). My question is, is there any way I can still use this trick when I onvert the word file into PDF?


2019-07-18 12:10:18

Amir

Hi
Thank you very much for your useful tips. I think we should insert the field in a shape to assign a macro to that shape.


2017-12-09 19:12:24

Graham Skan

I can't get this to work with a graphic in Word 2007. It's OK with text to click on.


2017-08-12 04:55:42

Barry

Does this only work for certain commands? I tried to do an Open in the text and nothing happens. I positioned my insertion point where I wanted the field to be, pressed CTRL+F9 and between the braces typed (without quotes) "MacroButton Open OpenIt". Then I pressed F9 and it collapsed to where I just saw the word "OpenIt". It's definitely a field, but when I click on it nothing happens. What's up? Thanks.


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.