Field codes: MacroButton field

The MacroButton field Inserts a macro (macro: An action or a set of actions that you can use to automate tasks. Macros are recorded in the Visual Basic for Applications programming language.) command, which you can run by double-clicking the results of a MACROBUTTON field. You can also click in the MACROBUTTON field and then press ALT+SHIFT+F9.

Security  Because macros can contain viruses, be careful about running them. Take the following precautions: run up-to-date antivirus software on your computer; set your macro security level to high; clear the Trust all installed add-ins and templates check box; use digital signatures; maintain a list of trusted publishers.


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

{ MACROBUTTON MacroName DisplayText }

 Note    A field code tells the field what to show. Field results are what’s shown in the document after having evaluated the field code. To toggle between viewing the field code and the field code results, press Alt+F9.



The name of the macro to run when you double-click the field result (field results: Text or graphics inserted in a document when Microsoft Word carries out a field's instructions. When you print the document or hide field codes, the field results replace the field codes.). The macro must be available in the active document (active document: The document in which you're working. Text you type or graphics you insert in Microsoft Word appear in the active document. The title bar of the active document is highlighted.) template (template: A file or files that contain the structure and tools for shaping such elements as the style and page layout of finished files. For example, Word templates can shape a single document, and FrontPage templates can shape an entire Web site.) or a global template (global template: Stores macros, AutoText entries, and custom toolbar, menu, and shortcut key settings that you can use while you work with documents based on any template. By default, the Normal template is a global template.).


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.


Double-clicking the following field runs the PrintEnvelope macro.


Double-click { MACROBUTTON PrintEnvelope Print Envelope } to print an envelope for this letter.


Double-click Print Envelope to print an envelope for this letter.

Applies to:
Word 2013, Word 2010, Word 2007, Word 2003