Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later 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 September 30, 2021)
This tip applies to Word 97, 2000, 2002, and 2003


7

You already know you can assign a macro to a button (a tool) on your 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. Position the insertion point where you want the button to appear.
  2. Press Ctrl+F9 to insert a field.
  3. Between the field brackets, type MacroButton, then the name of the command or macro you want the button to execute.
  4. Type the text you want displayed, or insert a graphic to be used as a button.
  5. 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 (1571) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) 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

Pasting without Updating References

Do you need to paste formulas without updating the references in whatever you are pasting? You can accomplish this, ...

Discover More

Renaming a File

Need to rename a file in a macro? It's easy to do using the Name command, as discussed in this tip.

Discover More

Automatically Printing a Range

If you want to automatically print a particular area of your worksheet at a specific time of day, you'll love this tip. ...

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 (menu)

Moving the Insertion Point to the Beginning of a Line

If you need to move the insertion point within your macro, then you'll want to note the HomeKey method, described in this ...

Discover More

Controlling the Bold Text Attribute

When processing a document in a macro, you may need to make some of your text bold. It's easy to do using the Bold ...

Discover More

Determining an Integer Value

One of the math functions you can use in your macros is the Int function. It provides a way for you to derive an integer ...

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 nine minus 5?

2020-11-21 11:52:50

Doug Minaker

Small correction here. Control + F9 does not work. You should use Control +Fn + F9.


2019-04-11 14:46:33

Joshua

Is it possible to execute a MacroButton like this with a single mouse click like a hyperlink...? Maybe via some background VBA...?


2018-11-05 14:41:09

Lee

Same. Cannot get a graphic to work in this context (instead of text).


2017-10-23 01:32:45

Brendan

Your tips appear to be quite popular...

https://davescomputertips.com/how-to-assign-a-macro-to-a-button-in-a-word-document/


2017-03-02 06:50:03

Riaan

Hi Allen
Thanks for the tip but when I use the field code with a button inserted it gives me a duplicate button which is inactive the one button work well but how do I remove the other inactive button?


2015-12-16 09:38:49

RussNeuman

I cannot get a picture to work with process.
I get works to work.
I have tried a jpg and insert clipart.
When ever I double click the picture the menu ribbon goes to tab format.
And that is all that happens.
I put text in the brackets as a 3rd parameter that works.
Any pointers?
Thx
Russ


2015-07-20 05:44:45

JMJ

Hi Allen,
Very good tip indeed. But I'm afraid I didn't catch the trick to use a graphic. Could you be more explicit, please?
Thank you.
J-M


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon 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.