Using "Found" Macros

Over the past few weeks we've been talking about recording macros to automate repetitive tasks in Microsoft Word. You can read the newsletters here:

http://www.topica.com/lists/editorium/read/message.html?mid=1706651129

http://www.topica.com/lists/editorium/read/message.html?mid=1706748016

http://www.topica.com/lists/editorium/read/message.html?mid=1706832239

What you may not know is that there are lots of "prerecorded" macros that will do all kinds of neat things. For example, subscribers to the Word-PC email list often post useful macros. You can learn more about the list (and search the list archives) here:

http://listserv.liv.ac.uk/archives/word-pc.html

You can also find macros on the Web by searching for the keywords "microsoft word macro" in your favorite search engine.

The macros you find will probably look something like this:


Sub CopyToSpike
If WordBasic.GetSelStartPos() <> _
WordBasic.GetSelEndPos() Then 'Text is selected
WordBasic.Spike 'Add entry to spike
WordBasic.EditUndo 'Undo the cut
Else
WordBasic.MsgBox "Please select text before running this macro.", _
"No Text Selected"
End If
End Sub

That particular macro copies text to the Spike. You can learn more about it here:

http://www.topica.com/lists/editorium/read/message.html?mid=1701697740

However, you don't have to understand how the macro works in order to use it. Here's how to put it (or any other macro) into Microsoft Word so it will be available when you need it:

1. Copy the text of the macro, starting with the first "Sub" and ending with the last "Sub." If the macro doesn't have those "Sub" lines at the beginning and end, skip step 8 in these instructions.

2. Click the "Tools" menu at the top of your Microsoft Word window.

3. Click "Macro."

4. In Word 97 or later, click "Macros."

5. Make sure "Macros Available In" shows "Normal.dot."

6. Type a name for the macro in the "Macro Name" box--probably the name used after the first "Sub." For this macro, that's "CopyToSpike."

7. Click "Create."

8. Delete the "Sub [macro name]" and "End Sub" lines that Word created in the macro window. The macro window should now be completely empty.

9. Paste the macro text at the current insertion point.

10. In Word 6 or 7, click "File," then "Close," then "Yes." In Word 97 or later, click "File," then "Close and Return to Microsoft Word."

The macro is now stored in your Normal template, ready for use.

To actually run the macro, do this:

1. Click the "Tools" menu.

2. Click "Macro."

3. In Word 97 or later, click "Macros."

4. Click the name of your macro to select it.

5. Click the "Run" button. (If you wanted to delete the macro, you could press the "Delete" button instead.)

And now, some cautions:

1. Make sure the macro was created for the version of Word you are using. Macros created for Word 97 and later versions will not run in earlier versions, and you can't just paste macros written for earlier versions into Word 97 and later. Also, later versions of Word have certain features that earlier versions don't, so a macro that uses features specific to Word 2000 won't run in Word 97.

2. Try to make sure the macro comes from a reasonably reliable source.

3. Before using a macro on a real document, test it on a backup copy of the document to *make sure* it does what you need it to do.

_________________________________________

READERS WRITE

Subscriber Meg Cox wrote:

Newly committed to automating whatever I can, I tried to automate changing a word or phrase in quotes to italics and removing the quotes. But with wildcards turned on, Find wouldn't find quotation marks at all. Any idea of where I might be going wrong?

I responded (in summary):

If your document has curly quotes, use ^0147 (for opening) and ^0148 (for closing). Those are the ANSI codes for curly quotation marks. If your document has straight quotes, use " in your find and replace.

As I tested this, I used this string in the Find What box:

"(*)"

And this string in the Replace With box (formatted as italic):

1

Or, if you have curly quotes, you could find this:

^0147(*)^0148

And replace with the same thing (formatted as italic):

1

This will cause you trouble if you have unmatched quotation marks. If that's the case, you might need to do something like this:

"([!"]@)"

Or this:

^0147([!^0147]@)^0148

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.

Recording a Find-and-Replace Macro

Today's article is the second in our series about recording macros. It covers basically the same procedure as last week's newsletter, but with an emphasis on finding and replacing problem items in an electronic manuscript. Watch for a complex (and useful) example of recording a macro in next week's article, coauthored with Dan A. Wilson, proprietor of The Editor's DeskTop (http://www.editorsdesktop.com/).

If you've been editing in Microsoft Word, you've probably come up with a list of items you find and replace on every manuscript. These might be picky little things like replacing multiple spaces with a single space, replacing underlining with italic, or replacing the word "catalogue" with "catalog" (or vice versa). If you're now doing such replacements manually, one after the other, you could record them all as a macro that you could run on any manuscript that needs it, saving yourself many hours over the course of a year. To do so, just follow the basic procedure outlined in last week's newsletter:

1. Start Word's macro recorder.

2. Do the stuff you want to record--in this case, find and replace all of the items on your list.

3. Stop the macro recorder.

(You can read last week's newsletter here: http://www.topica.com/lists/editorium/read/message.html?mid=1706651129.)

Got your list? Let's do it (on some junk files, of course):

1. START THE MACRO RECORDER

a. Click the "Tools" menu.

b. Click "Macro."

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

d. Type a name for your macro (something like "ReplaceMyStuff") in the "Macro name" box. (You can't use spaces in a macro name.)

e. Click the "OK" 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.

2. DO THE STUFF YOU WANT TO RECORD

Here's where you're going to find and replace all of those items on your list:

a. Go to the top of your document by pressing CTRL + HOME.

b. Click the "Edit" menu.

c. Click "Replace."

d. In the "Find What" box, type the string of characters or set the formatting you want to find. You can use wildcard strings if you like, as explained in Editorium Update over the past several issues. For example, if you wanted to find multiple spaces (to be replaced by a single space), you could enter a space followed by {2,} (which means "at least two") and then put a checkmark in the "Use Wildcards" (or "Use pattern matching") checkbox (you might have to click the "More" button before the checkbox is visible).

e. In the "Replace With" box, type the string of characters or set the formatting you want to use to replace the contents of the "Find What" box. For example, if you wanted to replace multiple spaces with a single space, you'd enter a single space.

f. Click "Replace All."

Now repeat those steps for each item you want to find and replace, setting the options and checkboxes in the Replace dialog as needed. (For a wonderfully useful example of transposing dates in a find-and-replace macro, see today's Readers Write column following this article.)

As you replace your items, don't forget that you're recording what you do. It's easy to get sidetracked and start editing, which would create a very strange (and potentially dangerous!) macro indeed. Resist the temptation. Just mechanically find and replace your items, one at a time. Don't think about anything else. *Be* the computer.

If you do make a mistake, don't panic. Just press CTRL + Z to undo the last find-and-replace operation. Your macro will record that, too, so no damage will be done, although your macro will later take longer to run because it includes that unnecessary find-and-replace operation and its reversal. Of course, you can always start over again if you really need to.

3. STOP THE MACRO RECORDER

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

That's it! You've recorded a macro to find and replace all those items you've been cleaning up manually. To play it back:

1. Click the "Tools" menu.

2. Click "Macro."

3. In Word 97 or later, click "Macros."

4. Click the name of your macro to select it.

5. Click the "Run" button. (If you wanted to delete your macro, you could press the "Delete" button instead.)

All of the items you recorded will be fixed automatically.

If the items you want to find and replace are fairly complicated (using wildcards, for example), you should try each one by hand and make sure it's working correctly before recording your macro.

If you don't have a list of items you regularly need to clean up, you might consider making one. As you edit your next project, just make a note every time you come across something you need to change more than a couple of times. Then use your list to record a find-and-replace macro that will do the work for you from now on.

Got that macro running? Sit back and sip your diet Coke. Life is sweet.

If you like the idea of cleaning up nitpicky items with a macro, you may be interested in our FileCleaner program, which you can learn about here:

http://www.editorium.com/14845.htm

If you'd like to run your macro on a bunch of documents all at once, you may be interested in our MultiMacro program, which you can learn about here:

http://www.editorium.com/14844.htm

_________________________________________

READERS WRITE

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

Transposing Dates

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

Subscriber Meg Cox wrote:

I just set up my first wildcard combination for a search and replace, and it works! I figured now was the time to take my walk on the wild side because I have a manuscript full of dates that are styled every which way. Now here's my question: I came up with the following to change various versions of month/day/year to day/month/year--but only for January.

Find what: (Ja[.a-z]@) ([0-9]{1,2}), ([0-9]{4})

Replace with: 2 January 3

I'd like to use this for all dates. I wonder if there's something like that [andh] combination that I can use to capture pairs of letters that begin months: Ja, Fe, Ma, Ap, and so on. But then again, maybe it won't work because I won't be able to specify the proper month in the "Replace with" box. This looks like the perfect opportunity to learn to do macros. Is a macro indeed the only one-click solution here?

I responded (in summary):

You're right--there's no easy way to do this with one click. You might consider recording a macro to do all of the combinations. Once you have it recorded, you can use it whenever you need it:

1. Click the "Tools" menu.

2. Click "Macro."

3. Click "Record New Macro."

4. Type a name for your macro (something like "TransposeDates") in the "Macro name" box.

5. If you want, assign the macro to a toolbar or keyboard combination.

6. Click the "OK" button. (The macro recording toolbar will appear.)

7. Record the Replace routine for each month. In other words, run your Replace routine for January, then for February, and so on.

8. Click the "Stop" button (the button with the blue square) on the macro recording toolbar.

In other words:

1. Start recording your macro.

2. Do the search-and-replace for January.

3. Do the search-and-replace for February.

4. Do the search-and-replace for March.

5. And so on through December.

6. Stop recording your macro.

Now, if you assigned the macro to a toolbar or key combination, you can use the toolbar or key combination to run the macro in the future. Or, you can do this:

1. Click the "Tools" menu.

2. Click "Macro."

3. Click "Macros."

4. Click the name for your macro (say, "TransposeDates") in the list of macros so it's selected.

5. Click the "Run" button.

That should do the job.

At this point, you'll have transposed all of the dates in the current document. But you'll also have created a macro that you can run in one step on any document in the future--a very handy thing to have.

After responding to Meg, I realized that there is one possible way to do what she was asking--transpose all of the dates in one fell swoop--*if* all of the months have been spelled out. Consider this wildcard string:

([JFMASOND][a-z]@) ([0-9]{1,2}), ([0-9]{4})

[JFMASOND] represents the first letter of each month, with duplicate letters removed.

[a-z]@ represents lowercase letters following the capital letter that starts the word.

There's a space after the name of the month.

[0-9]{1,2} represents the day of the month, whether one or two digits.

There's a comma and a space after the day.

[0-9]{4} represents four consecutive digits--in other words, the year.

The parentheses group the items so you can transpose them using "Find What Expression" wildcards in the "Replace With" box (after turning on "Use Wildcards," of course):

2 1 3

If some of the months have been abbreviated (Jan., Feb., Mar., etc.), you could transpose them by finding this (notice the period following the @ sign):

([JFMASOND][a-z]@.) ([0-9]{1,2}), ([0-9]{4})

and replacing with this:

2 1 3

If you've got a mix of abbreviated and unabbreviated dates, this string will find them all:

([JFMASOND][.a-z]@) ([0-9]{1,2}), ([0-9]{4})

and you can transpose them with this replacement string:

2 1 3

But of course, that won't spell out the abbreviated months. To do that, you'd need to record a macro that finds and replaces each month.

If you're going to use any of these wildcard strings, be sure to run them on some test documents to make sure they do what you need--and *don't* do what you don't need.

Macro Recording: The Basics

Over the next few weeks Editorium Update will explain how to record macros and use them to simplify repetitive editorial tasks in Microsoft Word. I'd like to thank subscribers Meg Cox, Allene Goforth, and Dan A. Wilson for suggesting this topic. I'm especially grateful to Dan, who is an editor's editor and Microsoft Word expert, for writing one of the articles with me. (Dan is the proprietor of The Editor's DeskTop, http://www.editorsdesktop.com/.) At Dan's suggestion, I'll start with the basics, get a little fancier next week, and then show you Dan's backbreaker of an example two weeks from now, so stay tuned. If you're a member of the Freelance email list who signed up for this series of articles, welcome! I hope you'll find the newsletter valuable enough to stay with us. If you've been reading the past newsletters on searching with wildcards, you'll want to look at our Readers Write column after the feature article for some additional information.

Macros--the mysterium tremendum, the sanctum sanctorum of Microsoft Word. Or, hey, just a great way to automate those mind-numbing, finger-breaking tasks you've been doing manually for so long. Recording a macro is like recording a song from the radio, only you're recording keystrokes instead of music. Here's the basic procedure:

1. Start the macro recorder (just like starting your tape recorder).

2. Do the stuff you want to record (such as typing text and running Word features).

3. Stop the macro recorder (just like stopping your tape recorder).

Well, shoot, that's not so hard.

Now let's take a simple but real (and useful) example. As you edit, you probably transpose characters a lot--I know I do. But it takes several keystrokes to do it:

1. Select the character you want to move. (Hold down SHIFT and press the RIGHT ARROW key.)

2. Cut the character. (Hold down CTRL and press X.)

3. Move to the place you want to put the character. (Press the LEFT ARROW key.)

4. Paste the character. (Hold down CTRL and press V.)

That's seven keystrokes altogether--keystrokes you do over and over, all of the time. Let's make life easier by recording them in a macro:

1. START THE MACRO RECORDER

a. Click the "Tools" menu.

b. Click "Macro."

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

d. Type a name for your macro (something like "TransposeCharacters") in the "Macro name" box. (You can't use spaces in a macro name.) If you're using our Editor's ToolKit or Editor's ToolKit Plus program, don't call the macro "TransposeCharacters," as our programs already use that name.

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

f. 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. I like function key 12 (F12) for this macro, but you can use CTRL + T (for "Transpose") or something else. Word will show you if the key or key combination is already assigned. If it is, you can try a different one or overwrite the current assignment. It's up to you. You may want to avoid combinations using the ALT key, which works with various letters to activate menu items and dialog controls. You can, however, use ALT + CTRL, ALT + SHIFT, or SHIFT + CTRL as part of your combination.

g. Click the "Assign" button.

h. 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.

2. DO THE STUFF YOU WANT TO RECORD

a. Select the character you want to move. (Hold down SHIFT and press the RIGHT ARROW key.)

b. Cut the character. (Hold down CTRL and press X.)

c. Move to the place you want to put the character. (Press the LEFT ARROW key.)

d. Paste the character. (Hold down CTRL and press V.)

Notice that this is the same procedure we used previously when we *weren't* recording a macro. In other words, we transposed the two characters just as we ordinarily would. Be careful not to use the cursor keys to move to a certain character before following this procedure. If you do, those keystrokes will become *part* of the procedure, and you'll end up recording all of those cursor movements. The idea is to record only the keystrokes you want the macro to do for you.

3. STOP THE MACRO RECORDER

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

That's it! You've recorded a macro. Now let's play it back:

1. Put your cursor between two characters you want to transpose.

2. Click the "Tools" menu.

3. Click "Macro."

4. In Word 97 or later, click "Macros."

5. Click the name of your macro to select it.

6. Click the "Run" button. (If you wanted to delete your macro, you could press the "Delete" button instead.)

That's one way to play back your macro. But since you assigned a key combination to the macro, it's a lot easier to do it like this:

1. Put your cursor between two characters you want to transpose.

2. Press the function key or key combination you've assigned to run the macro.

Presto! The two characters will be transposed.

In a way, what you've just done is create a feature (Transpose Characters) that Microsoft Word didn't have before. Are you beginning to see the possibilities?

You can learn more about Editor's ToolKit and Editor's ToolKit Plus, which have lots of handy macros like this one, here:

http://www.editorium.com/14842.htm

http://www.editorium.com/14857.htm

_________________________________________

READERS WRITE

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

Wildcard Inconsistency

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

Allene Goforth (agoforth@Aros.Net) discovered an interesting inconsistency in how wildcards are handled from one version of Microsoft Word to another. She wrote:

I finally started working on the wildcards yesterday. Everything was progressing smoothly until I got to Gandhi. I typed in Ghandi Gahndi Ganhdi and then I tried to change those to Gandhi, using G[andh]{3}i but it can't even find the above string--let alone change them.

[Allene was referring to our newsletter of March 28, 2001, which you can read here: http://www.topica.com/lists/editorium/read/message.html?mid=1706069286.]

G[andh][andh][andh][andh]i worked as did G[andh]@i so what am I doing wrong?

I responded (after doing some testing):

The string you are using--

G[andh]{3}i

--works great in Word 95, which is the version of Word I ordinarily use.

However, as you've learned, in Word 2000 it doesn't work. Instead, you have to use this:

G[andh]{4}i

In other Words, the wildcards seem to work differently in different versions of Word.

In Word 95, {3} means "three *more* of the previous expression."

In Word 2000, {3} means "*three* of the previous expression." Or so it seems.

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

Finding ANSI Codes on a Macintosh

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

Erika Buky (erikab@socrates.Berkeley.edu) found what seems to be a bug when searching for ANSI codes on a Macintosh. She wrote:

I've been reading the newsletters on wildcards with great interest and amazing my friends with my wizardry. I've noticed one problem, however, in trying to apply your clever solutions for transposing first names and last names in lists, and so on--things that require use of a code for a paragraph break.

[Erika was referring to our newsletter of April 18, 2001, which you can read here: http://www.topica.com/lists/editorium/read/message.html?mid=1706365638.]

I'm using Word 98 on a Mac (OS 8.1), and the code ^013 for a paragraph break seems to work only sporadically. When I'm doing searches like the one above, which requires this code at the end of the second search expression--^013([A-z]@) ([A-z]@)^013--the replace operation fails, I think because the paragraph break code is not recognized. (Word selects the first name, the space, and the first 2 letters of the second name, a string which meets the search criteria if you ignore the paragraph break code.)

Codes like ^09 for tabs are also treated inconsistently; sometimes I've had better luck dropping the initial zero.

Any idea why this might be so? Any possible solutions?

I responded:

I've just done some testing, and this seems to me to be a bug in Word. In both Word 98 and 2001 (on the Mac, of course), ^013 is recognized *unless* you specify that you're using wildcards. Then Word doesn't find the paragraph mark. Try searching for ^013 (or ^13) all by itself with the "Use wildcards" checkbox turned off and then on, and you'll see what I mean.

The Word 2001 documentation specifically says to use ^13 rather than ^p when using wildcards, but when you actually try it, it doesn't work. This is a real problem for Mac users, because it means there's no way to search for paragraph returns when using wildcards--unless you use a two-step operation. For example, with "Use wildcards" turned off, you could replace ^p with

^p

(the

being an arbitrary code) and then (with "Use wildcards" turned on) searching for

([A-z]@) ([A-z]@)

.

Thanks to Allene and Erika for their questions.

Two-Step Searching

While editing in Microsoft Word, I often need to find something that's *partially* formatted and replace it with something else. For example, let's say a manuscript has a bunch of superscript note numbers preceded by a space that's *not* in superscript. Here's an example (with carets indicating superscript):

Lorem ipsum dolor sit amet. ^1^

I'd like to have Word find all such spaces and replace them with nothing (in other words, delete them), but that doesn't seem possible. I can open Word's Replace dialog (Edit > Replace) and set the "Find What" box to superscript, but the space isn't superscript, and the manuscript has thousands of spaces that *don't* precede a superscript number. It also has numbers that aren't superscript (like 2001), so I can't just find spaces preceding numbers. What's an editor to do?

Find and replace the spaces in two steps rather than one:

1. Mark the superscript with codes.

2. Delete the spaces and codes.

STEP 1

To mark the superscript with codes, do this:

1. Open Word's Replace dialog by clicking the "Edit" menu and then "Replace."

2. Put your cursor in the "Find What" box and make sure the box is empty.

3. Click the "Format" button. (You may need to click the "More" button first.)

4. Click "Font."

5. Put a checkmark in the "Superscript" box.

6. Click the "OK" button. The "Find What" box should now be set to superscript.

7. Put your cursor in the "Replace With" box.

8. Type the following string in the "Replace With" box:

^&

9. Click "Replace All."

All of your superscript numbers will be replaced with themselves, preceded by , which is a code I just made up to indicate superscript. In other words, your sentences will now look like this:

Lorem ipsum dolor sit amet. ^1^

Feel free to make up your own codes for whatever you need (italic, bold, paragraph styles, and so on).

The other code in the "Replace With" box, ^&, is Microsoft Word's "Find What Text" code, which represents the text that was found (the superscript numbers). You can learn about it here:

http://www.topica.com/lists/editorium/read/message.html?mid=1703525514

STEP 2

To delete the spaces and codes, do this:

1. Open Word's Replace dialog by clicking the "Edit" menu and then "Replace."

2. Put your cursor in the "Find What" box by clicking it.

3. Type the following string in the "Find What" box:

(You can't see it very well in this newsletter, but there's a space in front of that code, and it needs to be there.)

4. Click the "No Formatting" button so you're no longer finding superscript, which is now represented by the code.

5. Put your cursor in the "Replace With" box and make sure the box is empty.

6. Click "Replace All."

All of the spaces in front of the codes (and thus in front of the superscript numbers) will be deleted, as will the codes themselves, leaving your sentences looking like this:

Lorem ipsum dolor sit amet.^1^

You can use this little two-step trick any time you need to find and replace partially formatted text. Now that you know how, that will probably be quite often.

ERRATA

In the April 18, 2001, issue of Editorium Update, I gave the following find-and-replace pattern for putting last name first in a list of names:

Pattern: G. B. Harrison, Ph.D.

Find What: ^013([A-z].) ([A-Z].) ([A-z]@,) (*)^013

Replace With: ^p3 1 2, 4^p

That first [A-z] wildcard range should have been given as [A-Z] (with a capital Z) to indicate a capital letter. [A-z] (with a lowercase z) will work, but it doesn't make the example as clear as it should have been.

_________________________________________

READERS WRITE

After reading last week's newsletter, subscriber Nancy Adess (naedit@earthlink.net) wrote, "Why would there be periods at all at the end of references in parens in the text? Why not just (Thoreau, Walden, p. 10)?"

I responded:

I realize I'm at odds with the Chicago Manual of Style (10.77) on this, but I think Chicago is wrong. Chicago style is like this, with no period at the end of the quotation and a period after the source citation:

"The improvements of ages have had but little influence on the essential laws of man's existence" (Thoreau, Walden [New York: Time Reading Program, 1962], p. 10).

To me, the period is *part* of the quotation--but we've just put it after the citation. However, if the sentence ends with a question or exclamation mark, Chicago keeps it with the quotation where it belongs:

"What is the nature of the luxury which enervates and destroys nations?" (Thoreau, Walden [New York: Time Reading Program, 1962], p. 13).

The placement of the question mark reveals the faulty reasoning behind moving the period--we didn't move the question mark, right? Also, we now have another problem: Since we're not going to move the question mark, how do we punctuate our citation? Chicago does it by leaving that period there--but in this case the period was never part of the sentence to begin with. This makes no sense at all--and besides, the period looks stupid hanging out there by itself. I think the sentence and the citation should be punctuated independently, like this:

"The improvements of ages have had but little influence on the essential laws of man's existence." (Thoreau, Walden [New York: Time Reading Program, 1962], p. 10.)

"What is the nature of the luxury which enervates and destroys nations?" (Thoreau, Walden [New York: Time Reading Program, 1962], p. 13.)

Simple. Sensible. Neat. Consistent. And not ugly.

And besides, I was trained by a marvelous, independent-thinking editor, and that's the way she did it. 🙂

In addition, using this style makes electronic manipulation simple because the sentence and the citation are both self-contained. For example, it's now an easy matter to write a macro that will turn parenthetical source citations into footnotes--or vice versa. If we take our first sentence, punctuated like this--

"The improvements of ages have had but little influence on the essential laws of man's existence." (Thoreau, Walden [New York: Time Reading Program, 1962], p. 10.)

--we can use a macro to:

1. Delete the space before the citation.

2. Delete the opening parenthesis.

3. Cut to the closing parenthesis.

4. Delete the closing parenthesis.

5. Create a footnote.

6. Paste the cut citation into the footnote.

7. Close the footnote.

That leaves our sentence looking like this (with carets indicating superscript):

"The improvements of ages have had but little influence on the essential laws of man's existence."^1^

And our note looking like this:

^1^Thoreau, Walden [New York: Time Reading Program, 1962], p. 10.

We could also use the macro successfully on our second sentence (the one with the question mark). But if we had followed Chicago style, we'd have to create separate macros for each kind of sentence and citation, and they'd be more complicated, too. (Our NoteStripper program includes macros that do this kind of stuff.)