Field codes: MacroButton field

Applies To
Word for Microsoft 365 Word for Microsoft 365 for Mac Word 2024 Word 2024 for Mac Word 2021 Word 2021 for Mac

The MacroButton field inserts a macro command, which you can run by double-clicking the field result. You can also click in the MacroButton field and then press ALT+SHIFT+F9.

To insert the Macrobutton field, select Insert > Quick Parts > Field. In the Field names list, select MacroButton, and then select OK.

Note

Because macros can contain viruses, be careful when running them. Run only macros from sources you trust.

Syntax

When you view the MacroButton field in your document, the syntax looks like this:

{ MACROBUTTON MacroName DisplayText ⁠}⁠

Note

This content applies to the desktop versions of Word for Windows and Mac (including Word with a Microsoft 365 subscription).

A field code tells the field what to display. To toggle between viewing the field code and the field code results, press Alt+F9 on Windows or Option+F9 on Mac.

Instructions

MacroName

The name of the macro to run when you double-click the field result. The macro must be available in the active document template or a global template.

DisplayText

The text or graphic to appear as the "button." You can use a field that results in text or a graphic, such as Bookmark or IncludePicture. The text or graphic must appear on one line in the field result; otherwise, an error occurs.

Example

Double-clicking the following field runs the PrintEnvelope macro.

Field:

Double-click ⁠{⁠ MACROBUTTON PrintEnvelope Button image ⁠}⁠ to print an envelope for this letter.

Result:

Double-click Button image to print an envelope for this letter.