in Macros

Recording a Complex Macro

[Editor's note: This week's article is the third in our series on macros, and I'm honored to have written it with Dan A. Wilson, proprietor of The Editor's DeskTop (http://www.editorsdesktop.com/). The example in the article is intentionally contrived. It's a nightmare task of repetitive processes. And it's long. But it's designed to teach you some things about recording macros. Dan and I hope you find it enlightening.]

The title "Recording a Complex Macro" looks intimidating, but actually *recording* a complex macro isn't really that hard. You just have to get firmly in mind what you want to do, step by step, and then do it.

~~~~~~~~~~~~

THE SCENARIO

~~~~~~~~~~~~

Suppose you have a Word document to edit--a 350-page dissertation with the title *Derived Humor: On the Roots of George Carlin's Comedy in the Works of Mark Twain.* The document has no block quotations, but it does have two hundred short Twain quotations and two hundred short Carlin quotations. The project editor wants you to make two lists of quotations so a couple of drudges can verify their accuracy. She wants the Twain quotations in one list and the Carlin quotations in another.

You'll have to create two new, blank documents. Save one with the name Twain and the other with the name Carlin. Twain will (eventually) contain all of the Twain quotations, and Carlin will (eventually) contain all of the Carlin quotations. After creating your new files, you'd have to do this (if you were doing the work by hand):

1. Scan through the dissertation file and find every Twain or Carlin quotation.

2. Select it (with its source citation).

3. Copy it to the clipboard.

4. Switch to Twain or Carlin, as appropriate.

5. Paste the quotation and source citation.

6. Hit ENTER to jump down a line so you're ready to paste the next quotation.

7. Switch back to the dissertation and hunt for the next quotation.

Whew! You'd have to select four hundred quotations, copy four hundred times, switch documents four hundred times, paste four hundred times, hit ENTER four hundred times, and switch back to your dissertation four hundred times. It would take you forever, and you'd have RSI pain before you were done.

Well, suppose we reduce that list to two tasks:

1. Select four hundred quotations (still a lot of work, but bear with us).

2. Record two macros that will do everything else when we hit their keyboard shortcuts.

That should reduce the time required for the job by at least eighty percent--maybe ninety! Not bad for a few seconds of macro recording.

Since we're going to select the quotations by hand, items 3 through 7 in the list above will make up the steps of our Twain macro:

3. Copy the quotation and citation to the clipboard.

4. Switch to Twain.

5. Paste the quotation and source citation.

6. Hit ENTER to jump down a line so you're ready to paste the next quotation.

7. Switch back to the dissertation and hunt for the next quotation.

~~~~~~~~~~~~~~~~~~~~~~~~~

RECORDING THE FIRST MACRO

~~~~~~~~~~~~~~~~~~~~~~~~~

You've got three documents open, right?

1. The dissertation itself. (We recommend that you actually create such a document to use while working through these instructions. It can include a bunch of junk text with the sample quotations from this article pasted here and there so you can actually see what happens when you record and use these macros.)

2. The empty Twain document.

3. The empty Carlin document.

You can check this by clicking the "Windows" menu on Word's menu bar, which should display a drop-down menu listing the three documents. You can switch to any of the documents by clicking its name on the menu. For now, switch to the dissertation, our starting place, and select the first Twain quotation:

"God, if you forgive my little jokes on thee, I'll forgive your great big joke on me" (ATS, p. 35).

With the quotation selected, let's record our first macro:

1. Click the "Tools" menu.

2. Click "Macro."

3. Click "Record New Macro" (in older versions of Word, click the "Record" button).

4. Type a name for the macro ("Twain") in the "Macro name" box.

5. Under "Assign macro to," click the "Keyboard" button.

6. With your cursor in the "Press new shortcut key" box, press the function key or key combination you want to use to run the macro, such as SHIFT + CTRL + T (for Twain).

7. Click the "Assign" button.

8. Click the "Close" button. The macro recording toolbar will appear with two buttons--the first to stop recording and the second to pause recording if you need to. That means the macro recorder is now recording what you do.

9. Copy the quotation and citation to the Clipboard by pressing CTRL + c.

10. Switch to the Twain document by clicking the "Windows" menu and then clicking "Twain."

11. Paste the quotation and citation by pressing CTRL + v.

12. Hit ENTER to jump down a line so you're ready to paste the next quotation.

13. Switch back to the dissertation by clicking the "Windows" menu and then clicking "Dissertation."

14. Click the "Stop" button (the button with the blue square) on the macro recording toolbar to stop recording.

~~~~~~~~~~~~~~~~~~~~~~~~~~

RECORDING THE SECOND MACRO

~~~~~~~~~~~~~~~~~~~~~~~~~~

Now let's get ready to record our Carlin macro. In the dissertation, select the first Carlin quotation:

"One tequila, two tequila, three tequila, floor" (BFP, p. 29).

With the quotation selected, let's record our second macro:

1. Click the "Tools" menu.

2. Click "Macro."

3. Click "Record New Macro" (in older versions of Word, click the "Record" button).

4. Type a name for the macro ("Carlin") in the "Macro name" box.

5. Under "Assign macro to," click the "Keyboard" button.

6. With your cursor in the "Press new shortcut key" box, press the function key or key combination you want to use to run the macro, such as SHIFT + CTRL + C (for Carlin).

7. Click the "Assign" button.

8. Click the "Close" button. The macro recording toolbar will appear with two buttons--the first to stop recording and the second to pause recording if you need to. That means the macro recorder is now recording what you do.

9. Copy the quotation and citation to the Clipboard by pressing CTRL + c.

10. Switch to the Carlin document by clicking the "Windows" menu and then clicking "Carlin."

11. Paste the quotation and citation by pressing CTRL + v.

12. Hit ENTER to jump down a line so you're ready to paste the next quotation.

13. Switch back to the dissertation by clicking the "Windows" menu and then clicking "Dissertation."

14. Click the "Stop" button (the button with the blue square) on the macro recording toolbar to stop recording.

~~~~~~~~~~~~~~~~~~

RUNNING THE MACROS

~~~~~~~~~~~~~~~~~~

Now, with both macros recorded, we're ready to go to work. Here's the procedure:

1. In the dissertation document, select a quotation, either by Twain or by Carlin.

2. If the quotation is by Twain, press SHIFT + CTRL + T.

3. If the quotation is by Carlin, press SHIFT + CTRL + C.

4. Keep going until all of the quotations are done.

When you're finished, your Twain document will have all of the Twain quotations, and the Carlin document will have all of the Carlin quotations.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

AUTOMATICALLY SELECTING THE QUOTATIONS

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Still too much work? Let's see if we can get the macros to select the quotations automatically.

We'll start with the Twain quotations. What do they have in common? They're all in quotation marks, and they're all followed by an ATS source citation in parentheses. If you've read our wildcard articles over the past few months, you know we could find (and thus automatically select) those quotations with this wildcard string:

"[!"]@" (ATS*).

What's that mean?

" is a quotation mark (which opens a quotation).

[!"]@ means "Find any additional characters except a quotation mark." (We need this to keep from including parts of other quotations.)

" is another quotation mark (which closes a quotation).

Then there's a space.

( represents an opening parenthesis. (Remember, since a parenthesis is itself a wildcard, we have to use a backslash to tell Word to treat this one as a character.)

ATS is our Twain source.

* represents any other characters following the source.

) represents a closing parenthesis.

Finally, there's a period.

Taken together, this string of characters will find our Twain quotation and others like it. And we can do the same thing with our Carlin quotations, using BFP rather than ATS in our wildcard string. So let's record our macros again, this time including this fancy way of finding and selecting them. Remember, you'll need to have three documents open:

1. The dissertation itself.

2. The empty Twain document.

3. The empty Carlin document.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

RE-RECORDING THE FIRST MACRO

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Then, with the dissertation as the active document, follow this procedure:

1. Click the "Tools" menu.

2. Click "Macro."

3. Click "Record New Macro" (in older versions of Word, click the "Record" button).

4. Type a name for the macro ("Twain") in the "Macro name" box. If Word asks if you want to replace the existing macro, click "Yes."

5. Under "Assign macro to," click the "Keyboard" button.

6. With your cursor in the "Press new shortcut key" box, press the function key or key combination you want to use to run the macro, such as SHIFT + CTRL + T (for Twain).

7. Click the "Assign" button.

8. Click the "Close" button. The macro recording toolbar will appear with two buttons--the first to stop recording and the second to pause recording if you need to. That means the macro recorder is now recording what you do.

9. Click the "Edit" menu.

10. Click the "Find" menu item.

11. In the Find dialog's "Find What" box, enter the string we discussed:

"[!"]@" (ATS*).

12. Put a checkmark in the "Use wildcards" or "Use Pattern Matching" checkbox. (You may need to click the "More" button before this is available.)

13. Click the "Find Next" button. Word will find and select the first Twain quotation and citation.

14. Click the "Cancel" button to close the Find dialog.

15. Copy the quotation and citation to the Clipboard by pressing CTRL + c.

16. Switch to the Twain document by clicking the "Windows" menu and then clicking "Twain."

17. Paste the quotation and citation by pressing CTRL + v.

18. Hit ENTER to jump down a line so you're ready to paste the next quotation.

19. Switch back to the dissertation by clicking the "Windows" menu and then clicking "Dissertation."

20. Click the "Stop" button (the button with the blue square) on the macro recording toolbar to stop recording.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

RE-RECORDING THE SECOND MACRO

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Again, with the dissertation as the active document, follow this procedure:

1. Click the "Tools" menu.

2. Click "Macro."

3. Click "Record New Macro" (in older versions of Word, click the "Record" button).

4. Type a name for the macro ("Carlin") in the "Macro name" box. If Word asks if you want to replace the existing macro, click "Yes."

5. Under "Assign macro to," click the "Keyboard" button.

6. With your cursor in the "Press new shortcut key" box, press the function key or key combination you want to use to run the macro, such as SHIFT + CTRL + C (for Carlin).

7. Click the "Assign" button.

8. Click the "Close" button. The macro recording toolbar will appear with two buttons--the first to stop recording and the second to pause recording if you need to. That means the macro recorder is now recording what you do.

9. Click the "Edit" menu.

10. Click the "Find" menu item.

11. In the Find dialog's "Find What" box, enter this string:

"[!"]@" (BFP*).

12. Put a checkmark in the "Use wildcards" or "Use Pattern Matching" checkbox. (You may need to click the "More" button before this is available.)

13. Click the "Find Next" button. Word will find and select the first Carlin quotation and citation.

14. Click the "Cancel" button to close the Find dialog.

15. Copy the quotation and citation to the Clipboard by pressing CTRL + c.

16. Switch to the Carlin document by clicking the "Windows" menu and then clicking "Carlin."

17. Paste the quotation and citation by pressing CTRL + v.

18. Hit ENTER to jump down a line so you're ready to paste the next quotation.

19. Switch back to the dissertation by clicking the "Windows" menu and then clicking "Dissertation."

20. Click the "Stop" button (the button with the blue square) on the macro recording toolbar to stop recording.

~~~~~~~~~~~~

FINISHING UP

~~~~~~~~~~~~

Now you can go through the dissertation pressing SHIFT + CTRL + T to automatically select and copy the Twain quotations and then pressing SHIFT + CTRL + C to automatically select and copy the Carlin quotations. It will still take some time, but it will be *much* faster than doing all of the work by hand. Most important, by going through all of this, you've probably learned quite a bit about how to record macros and use them to simplify your work. And that's what we were *really* trying to accomplish.