March 5, 2014

Assigning a Word Macro to a Button

Filed under: Main — Tags: , — admin @ 12:01 am

I prefer using keyboard shortcuts for my macros, but there are only so many keys on the keyboard. The Ribbon, however, remains a vast, fertile land into which you can add all sorts of buttons, as does Word’s Quick Launch bar.

For this week’s Word Macro lesson, you’ll need to fire up a new document. The goal is to create a macro and assign it to a button on the Ribbon. This process is but a small appetizer, teasing you into the full-on power of the Word macro.

This macro example deletes a line of text, so it’s pretty simple but not particularly useful to anyone. The point is getting that command onto a toolbar button.

Start by opening a new document, which you don’t need to save. If you need review on how to display the Developer tab on the Ribbon, click here. Click here for a review on how to create a basic macro. Otherwise, if you’re up to speed, follow these steps:

1. Fill the document with paragraphs of random text.

The simplest way to create random text is to type =rand() on a line by itself and press the Enter key.

2. Click the Developer tab.
3. Click the Record Macro button.
4. For the Macro name type Delete_Line.
5. From the Store Macro In drop-down menu, choose Document1 (document) for the current document.

So far things look similar to Figure 1, which shows the Record Macro dialog box.

Figure 1. The Record Macro dialog box.

Figure 1. The Record Macro dialog box.

6. Click the Button button.

The Word Options dialog box appears, shown in Figure 2. This is the same Word Options dialog box used to change Word’s settings, but also to customize the Ribbon and (shown in Figure 2) the Quick Access toolbar.

Figure 2. Adding the macro to the Quick Access toolbar. (Click to embiggen.)

Figure 2. Adding the macro to the Quick Access toolbar. (Click to embiggen.)

The Delete_Line macro appears on the left in Figure 2. The buttons on the Quick Access toolbar show up on the right.

7. Click to select the Delete_Line macro on the left side of the dialog box.
8. Click the Add button (in the middle of the dialog box).
9. You can use the Up or Down buttons to move the Delete_Line macro up or down in the list.
10. Click the OK button.

The Delete_Line macro now appears atop the Word window, nestled in the Quick Actions toolbar. You’re now ready to record the macro:

11. Press the Home key to ensure that the cursor is at the start of the line.
12. Press Shift+End to select to the end of the line.
13. Press Delete to remove the line.
14. Click the Stop Recording button.

The Delete_Line macro is now created, saved as a button on the Quick Access toolbar. To use it, click the button.

Two quick answers for you:

Yes! You can change the look of the button. Word features a button editor that lets you create unique buttons.

Yes! You can place the button on the Ribbon. You can even create your own, custom Ribbon tab just for your own commands.

I’ll be divulging these and other Word macro secrets over the next few weeks.

Feel free to discard the document and the macro, or save them. It’s up to you. But if you choose to save, you encounter something called the macro-enabled Word document. I discuss that topic next week.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.


Powered by WordPress