Assigning an existing macro to a menu item, toolbar button or keyboard shortcut

When you create a macro, either in the Visual Basic Editor or by recording it, you can run it from the Tools/Macro/Macros dialog:

the Macros dialog

But you can also run macros from a menu, by clicking a toobar button, or by typing a keyboard shortcut. This is much more convenient when you need to run the macro frequently.

This page assumes you have already created or recorded a macro.

Assigning an existing macro to controls

Macros live in modules, which are part of a document or template. By default, recorded macros are placed in the Normal template in the NewMacros module.

The project browser

You can, however, rename the module, or copy and paste a macro to another module. Modules can have many macros, or they can have none (a module may be used to store global variables, for instance).

Put an existing macro on the menu

To place a macro on a menu so that you can select it just like any other menu item, choose Tools/Customize/Customize Toolbars/Menus... The Customize dialog will open and an extra toolbar will appear just underneath the menu bar, that contains all the controls for the menu. Click on Commands, then scroll down on the left hand pane of the dialog, and click on Macros.

the customize toolbars/menus dialog

Select your macro from the right-hand pane and drag it to the menu item you want to place it in. For instance, to place MyMacro in the Tools menu, drag the icon to the Tools dropdown then place it where you want it - the black bar indicates where it will go:

placing the macro on the menu

Click OK. Your Tools menu now has a new control - the Normal.NewMacros.MyMacro item. See below for instructions on how to change the macro name in the menu.

Place an existing macro on a toolbar

Assigning a macro to a toolbar is similar to putting a macro on a menu. Choose Tools/Customize/Customize Toolbars/Macros... to display the Customize dialog. Click the Commands tab, and choose Macro from the Categories listbox. Drag your macro's icon to the toolbar of your choice

dragging a macro icon to a toolbar

a thick black line will show you where the button will be placed. The button's face will have the name of the macro. See below for instructions on how to change the macro name on the button.

Assign a keyboard shortcut to an existing macro

You can assign a keyboard shortcut to a macro when you record one, but macros you write (or copy from other sources) can also be assigned a shortcut, just as any other command. Choose Tools/Customize/Keyboard... and choose Macros from the Categories listbox.

keyboard shortcut dialog

Select your macro and type shortcut in the indicated textbox. Make sure you click Assign. If you click OK instead, the shortcut won't be saved.

Changing the macro name or button appearance

Having a macro name of Normal.NewMacros.MyMacro is very specific as to where the macro's located, but you don't really need to know the location, usuually, and on buttons, it takes up a lot of real estate.

Changing the macro name in a menu

Choose Tools/Customize/Customize Toolbars/Macros... In the menu toolbar, locate your macro, Ctrl- or right-click the item and choose Properties

the menu item properties dialog

Change the name to whatever you like. It changes only the name on the menu, not the name of the macro itself.

Changing the macro name on a toolbar

Changing the button name is similar to changing the name in a menu. You don't have to go through the hassle of choosing Tools/Customize/Customize Toolbars/Macros... however. Just Ctrl- or right-click on the button and choose Properties from the pop-up menu.

button pop-up menu

Change the name as to whatever you like in the Properties dialog.

Changing the Button Face

You can change the button face from the name of the macro to a pre-set or custom icon, just like the built-in buttons. To do so, Ctrl- or right-click on the button, and choose Properties from the pop-up menu. In the Properties dialog, choose Default Style from the View pop-up menu:

Property dialog's view menu

Now choose an icon from the Button Image pop-up menu

Property dialog Button Image dropdown

To copy a button image from another toolbar button, even from a button in a different Office application, in that button's Properties dialog, chose Copy Button Image from the Button Image pop-up menu, then choose Paste Button Image in the Button Image pop-up in your macro button's Properties dialog. See Copy an image from one toolbar or menu command to another in Word Help.

You can also create your own custom button faces - just copy any graphics image from a graphics program and use the Paste Button Image command. The graphic will be scaled to fit, so smaller images work best (20 x 20 pixels is the default button resolution). See Copy an image from a graphics program to a toolbar button or menu command in Word Help.

Valid XHTML 1.1Valid CSSMade on a Macintosh