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

Posted in Macros | Leave a comment

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.

Posted in Macros | Leave a comment

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.

Posted in Macros | Leave a comment

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.

Posted in Macros | Leave a comment

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

Posted in Editing | Leave a comment

Wildcards in the Real World

I hope you've enjoyed the wildcard "tutorial" articles in Editorium Update over the past few weeks. If you haven't read them, I'd recommend that you do so in order to understand this week's article. You can review the whole series here, starting with the March 20, 2001, issue:

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

This week I thought you might be interested in seeing some of the wildcard combinations I've used recently in an actual editing project. Maybe you'll find them useful too.

EXAMPLE 1

The manuscript I've been working on has lots of parenthetical references like this:

(Thoreau, Walden, p 10.)

You'll notice that there's no period after the p. To fix these references, I used the following string in Microsoft Word's "Find What" box in the Replace dialog (Edit > Replace), with "Use Wild Cards" (or "Use Pattern Matching") turned on:

p ([0-9]@.))

That's an odd-looking thing with its double parentheses, but its meaning becomes clear when you consider that the first closing parenthesis represents the closing parenthesis of the reference. The backslash in front of it tells Word to treat it as a character rather than the end of a group "expression." So the whole string says this:

1. Find a p followed by a space.

2. Find, as a group, one or more digits followed by a period followed by a closing parenthesis.

I put this in the "Replace With" box:

p. 1

And that string says this:

1. Replace the p followed by a space with p followed by a period and a space.

2. Replace the rest of the "Find What" string (the group in parentheses) with itself.

When I was finished finding and replacing, the references looked like this:

(Thoreau, Walden, p. 10.)

EXAMPLE 2

Here's another example from the manuscript I've been working on:

(Genesis 8:26)

You'll notice that there's no period before the closing parenthesis. Wanting to fix these, I put this string in the "Find What" box:

([0-9]@:[0-9]@))

It says:

1. Find, as a group, any number of digits followed by a colon followed by any number of digits.

2. Find a closing parenthesis character.

I put this in the "Replace With" box:

1.)

And that string says:

1. Replace the group with itself.

2. Replace the closing parenthesis with a period and a closing parenthesis.

When I was finished finding and replacing, the references looked like this:

(Genesis 8:26.)

"Why," you may be wondering, "did you have to use wildcards? Why didn't you just find a closing parenthesis and replace it with a closing parenthesis and a period, like this:

Find What:

)

Replace With:

.)

I couldn't do that because the manuscript had other parenthetical items (like this one) that didn't need a period. Using wildcards makes it possible to find exactly the items you want and ignore those you don't.

EXAMPLE 3

The manuscript had Bible references that looked like this:

II Corinthians

II John

II Kings

I wanted them to look like this:

2 Corinthians

2 John

2 Kings

I put this in the "Find What" box:

II ([A-Z])

The string says:

1. Find I followed by I followed by a space.

2. Find any capital letter.

And I put this in the "Replace With" box:

2 1

That string says:

1. Replace the II with a 2.

2. Replace the capital letter with itself.

Worked like a charm.

"Why," you ask, "didn't you just replace II with 2 throughout the manuscript rather than use wildcards?" Well, I could have. But I was also thinking about other entries like these:

I Corinthians

I John

I Kings

Obviously, I couldn't just replace I with 1 throughout the manuscript, so I used this string in the "Find What" box:

I ([A-Z])

And I used this string in the "Replace With" box:

1 1

And that took care of the problem.

I hope you're beginning to see how powerful wildcards can be and how much time they can save while you're editing a manuscript. Using wildcards, you can quickly fix repetitive problems that would take hours to correct by hand. I highly encourage you to try them, but I also urge you to back up your documents and experiment on some junk text before using wildcards in the "real world." Also, try finding and replacing items individually before replacing all of them globally. Then you'll know that the wildcards you're using actually do what you need to have done.

Posted in Editing | Leave a comment

Using the "Find What Expression" Wildcard

For the past few weeks we've been talking about using wildcards to find and replace text in Microsoft Word. Last week I introduced the "Find What Expression" wildcard (n) and promised to show you how to use it to move things around.

Let's say you've got a list of authors, like this:

Emily Dickinson

Ezra Pound

Willa Cather

Ernest Hemingway

and you need to put last names first, like this:

Dickinson, Emily

Pound, Ezra

Cather, Willa

Hemingway, Ernest

You can use the "Find What Expression" wildcard to do this in a snap.

Start the Replace dialog (Edit > Replace) and put a check in the "Use wildcards" or "Use Pattern Matching" box (you may need to click the "More" button before this is available). Then, in the "Find What" box, enter this:

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

If you've been reading Editorium Update, you'll probably understand these codes and wildcards:

^013 represents a paragraph mark.

[A-z] represents any single alphabetic character, from uppercase A to lowercase z.

@ represents any additional occurrences of the previous character--in this case, any single alphabetic character, from uppercase A to lowercase z.

() groups [A-z]@ together as an "expression" representing an author's first name. (This grouping is the key to using the "Find What Expression" wildcard in the "Replace With" box.)

The space after the first ([A-z]@) expression represents the space between first name and last name.

The next ([A-z]@) group represents the author's last name.

The final ^013 represents the paragraph mark after the name.

Now, in the "Replace With" box, enter this:

^p2, 1^p

The ^p codes represent paragraph marks. "Wait a minute," you say. "You just used ^013 for a paragraph mark. Why the change?"

Excellent question. The answer has two parts:

1. If we could use ^p in the "Find What" box, we would. But since Word won't let us do that when using wildcards (it displays an error message), we have to resort to the ANSI code, ^013, instead. You can learn more about this here:

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

2. If we use ^p in the "Replace With" box, Word retains the formatting stored in the paragraph mark (a good thing). If we use ^013, Word loses the formatting for the paragraph (a bad thing). In a list of author names, this probably doesn't matter, but you'll need to know this when finding and replacing with codes in more complicated settings.

Continuing with our example, ^p2, 1^p:

2 is the "Find What Expression" wildcard for our *second* expression (hence the 2) in the "Find What" box--in other words, it represents the last name of an author in our list.

The comma follows this wildcard because we want a comma to follow the author's last name.

A space follows the comma because we don't want the last and first names mashed together, like this: "Pound,Ezra."

1 is the "Find What Expression" wildcard for our *first* expression (hence the 1) in the "Find What" box--in other words, it represents the first name of an author in our list.

Now click the "Replace All" button. The authors' names will be transposed:

Dickinson, Emily

Pound, Ezra

Cather, Willa

Hemingway, Ernest

You've always wondered how to do that, right? But now you're wondering about middle initials. And middle names. And Ph.D.s.

All of those make things more complicated. But here, in a nutshell, are the Find and Replace strings you'll need for some common name patterns (first last, first middle last, first initial last, and so on). First comes the name pattern, then the Find string, and finally the Replace string, like this:

NAME PATTERN

FIND WHAT

REPLACE WITH

William Shakespeare

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

^p2, 1^p

Alfred North Whitehead

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

^p3, 1 2^p

Philip K. Dick

^013([A-z]@) ([A-Z].) ([A-z]@)^013

^p3, 1 2^p

L. Frank Baum

^013([A-Z].) ([A-z]@) ([A-z]@)^013

^p3, 1 2^p

G. B. Harrison, Ph.D.

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

^p3 1 2, 4^p

J.R.R. Tolkien

^013([A-Z].)([A-Z].)([A-Z].) ([A-z]@)^013

^p4, 123^p

That list doesn't show every pattern you'll encounter, but it should provide enough examples so you'll understand how to create new patterns on your own--which is the whole point of this article. Once you've created all of the patterns you need, you could record all of that finding and replacing in a single macro that you could run whenever you need to transpose names in a list.

_________________________________________

READERS WRITE

After reading last week's newsletter, Mary L. Tod (mtod@earthlink.net) wrote:

In your Editorium Update for today, is it necessary to enclose the space in parentheses? Since it isn't being replaced by itself, can't the expression in the Find box be reduced to

(^013[0-9]@.)

(with just the space entered after the first expression)?

Mary is absolutely right about this. I put the space in parentheses because I wanted to briefly introduce the idea that you could have more than one "Find What Expression" wildcard--in this case, 2. For that to work, the space has to be in parentheses so it's recognized as an expression. But I didn't actually *use* the 2 in the example, so a simple space would have worked just fine.

Mary continued:

In a related question, does the @ symbol in the wildcard field also allow for no repeats of the previous character? Otherwise, it would start the list at 10, wouldn't it?

2. followed by a number ([0-9])

3. followed by one or more numbers (@)

Again, this is right on the mark. The @ really means "followed by one or more numbers *if there are any.*" A more technical way to put it is "followed by *zero* or more numbers."

Thanks to Mary for her astute comments.

Posted in Editing | Leave a comment

Wildcard Grouping

For the past few weeks we've been talking about using wildcards to find and replace text in Microsoft Word. This week we'll discuss wildcard grouping, which is simply a way of telling Word that you want certain wildcards to be used together as a unit.

Continuing with our example from last week, let's say that you're editing a document with lots of numbered lists, like this:

1. Lorem ipsum dolor sit amet.

2. Ut wisi enim ad minim veniam.

3. Duis autem vel eum iriure dolor.

Now let's say that you want to replace the space after each number and period with a tab. After calling up the Replace dialog (Edit > Replace) and putting a check in the "Use wildcards" or "Use Pattern Matching" box, you could enter the following string of characters into the "Find What" box:

^013[0-9]@.

(You can't see it, but there's a space on the end of that string, and it needs to be included.) As you probably recall from the past few weeks, this tells Microsoft Word to do the following:

1. Find a paragraph mark (^013)

2. followed by a number ([0-9])

3. followed by one or more numbers (@)

4. followed by a period (.)

5. followed by a space ( ).

But that still won't let us replace that space with a tab. Why? Because there's no way to replace the space independently of the rest of the string--whatever the string finds *includes* the space.

So let's try this:

(^013[0-9]@.)( )

Notice that we've grouped the wildcards and other characters together with parentheses. (In case you can't tell, that's our uncooperative space between the last two parentheses.) Such groups, for reasons known only to the mathematically minded, are called "expressions," and in this case there are two of them:

1. (^013[0-9]@.)

2. ( )

Grouping things together like this makes it possible to refer to each group independently in the "Replace With" box--a wonderful thing! So in the "Replace With" box, we'll enter this string:

1^t

That "1" is an example of the little-known "Find What Expression" wildcard, which lives deep in the wilds of Redmond, Washington, and only comes out at night. It's a backslash followed by the number one, and it tells Word to replace whatever is found by the first expression--

(^013[0-9]@.)

--with whatever the first expression finds. (Yes, you read that correctly.) In other words, Word replaces whatever the first expression finds with *itself.* That seems strange, but it means we can treat the second expression--

( )

--as an independent unit, which is exactly what we need to do. (By the way, "Find What Expression" wildcards are the only wildcards that can be used in the "Replace With" box. They are simply a backslash followed by a number.)

The ^t, of course, is the code for a tab, as explained in the November 14, 2000, issue of Editorium Update:

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

You'll notice that we haven't included a "2" code, which would replace something with whatever is found by our *second* expression, the space in the parentheses. Since we haven't included that code, the space will be replaced by nothing--in other words, it will be *deleted* during the Find and Replace. So the relationship between the wildcards in the "Find What" string and the "Replace With" string is something like this:

FIND WHAT: REPLACE WITH:

(^013[0-9]@.) > 1 (followed by a tab: ^t)

( ) > [nothing]

Now let's try using them:

1. Start the Replace dialog (Edit > Replace).

2. Put a check in the "Use wildcards" or "Use Pattern Matching" box (you may need to click the "More" button before this is available).

3. In the "Find What" box, enter this:

(^013[0-9]@.)( )

4. In the "Replace With" box, enter this:

1^t

5. Click the "Replace All" button.

Presto! All of the spaces after your numbers will be replaced with tabs, and your list will now look like this:

1.Lorem ipsum dolor sit amet.

2.Ut wisi enim ad minim veniam.

3.Duis autem vel eum iriure dolor.

To me, this is like magic, and it comes in handy more often than you might think. I hope you'll find it useful! In the future, I'll try to provide other examples that you can apply in your day-to-day work. Next week I'll show you how to use "Find What Expression" codes to move things around.

_________________________________________

READERS WRITE

After reading our past few newsletters on wildcard searching, a subscriber wrote, "Use Pattern Matching does not appear to be an option in my Word program."

I apologize for not explaining this. In Microsoft Word 6 and 95, "Use Pattern Matching" is an option in the Find and Replace dialogs, and selecting this option tells Word that you're going to use wildcards. In Word 97 and later, this option is simply called "Use Wildcards." To see this option, you may need to click the "More" button in the Find and Replace dialogs.

Posted in Editing | Leave a comment

Wildcard Ranges

Last week we discussed using wildcard combinations to find text in a Microsoft Word document. You can read last week's newsletter here:

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

This week we'll talk about wildcard ranges, which you'll probably use a lot.

Wildcard ranges are fairly simple. You just use the [-] wildcard to tell Microsoft Word what to find. Let's continue with our example from last week:

b?[td]

As you probably recall, this tells Word to find the letter b followed by any single character followed by either t or d. In other words, it will find "bet," "but," "bit," "bat," "bed," "bud," "bid," "bad," and so on.

But what if we wanted to find "bat," "bad," "bet," and "bed" but NOT "bit," "bid," "bud," and "but"? After bringing up the Find dialog (Edit > Find) and turning on "Use Pattern Matching" (you may need to click the "More" button before this is available), we could use this wildcard combination in the "Find What" box:

b[a-e][td]

This tells Word to find the letter b followed by any letter from a to e (in other words, a, b, c, d, or e) followed by t or d. (The range *must* be in ascending order--in other words, from a "lower" letter [such as a] to a "higher" letter [such as z].)

Here's another way to approach this:

b[!f-z][td]

Notice the exclamation mark at the front of the "range" wildcard. The exclamation mark tells Word to find every character *except* those specified--in this case, the letters f through z. This wildcard combination, too, will find "bat," "bad," "bet," and "bed" but not "bit," "bid," "bud," and "but."

Here's a range that I use all the time:

[0-9]

This little beauty finds any occurrence of a digit. What's that good for? Let's say you're editing a document with lots of numbered lists, like this:

1. Lorem ipsum dolor sit amet.

2 Ut wisi enim ad minim veniam.

3. Duis autem vel eum iriure dolor.

Did you notice that the number 2 has no period? Good! You must have "the eye." But if you have several long lists, you might want to let Word find these problem numbers for you. To do so, try this wildcard string:

^013[0-9]@[!.]

Pretty cryptic. But if you've been reading Editorium Update, you can probably figure this out:

^013 is the numeric code for a carriage return.

[0-9] represents any digit.

@ tells Word to find one or more occurrences of the previous expression (in this case, any digit). This is necessary in case you have lists with two-digit (or longer) numbers.

[!.] tells Word to find any character *except* a period.

Piece of cake.

Here are two other wildcard ranges you might find useful:

[a-z] represents any occurrence of a lowercase letter.

[A-Z] represents any occurrence of an uppercase letter.

Remember, too, that you can use the [] wildcard (without a hyphen) to specify a whole group of characters *without* using a range. For example, this wildcard will find various kinds of punctuation:

[.,;:?!]

You may be wondering about the backslash () in front of the question and exclamation marks. The backslash tells Word to treat the following character *as* a character and not as a wildcard. (Remember, ? is the wildcard for a single character, and ! is the wildcard for "except.")

Don't be afraid to try all of these wildcard combinations and ranges for yourself (on some junk text, of course). As you experiment, you'll better understand what works and what doesn't. Then, when the need to use wildcards arises (which it will), you'll be ready.

Next week, we'll look at expression grouping and the little-known "Replace With" wildcard.

You can learn more about using numeric codes (such as that ^013 representing the carriage return) here:

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

And you can learn more about using junk text (such as "Lorem ipsum dolor sit amet") here:

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

_________________________________________

READERS WRITE

Our last newsletter used misspellings of the name "Gandhi" as an example, noting that it would be possible to use the wildcard string G[andh][andh][andh][andh]I to find the misspellings "Ghandi," "Gahndi," and "Ganhdi" all in one pass. Subscriber Glade Lyon (my dad!) wrote:

"It seems to me that your string should be G[andh][hand][ahnd][anhd]i."

Thinking that other readers might see this the same way, I'm including my response here:

I see what you're thinking--that each set of bracketed letters is an alternative spelling. No, *each set* of bracketed letters represents *one* letter in the word. [andh] will find either an "a," an "n," a "d," or an "h," whichever it comes to first. So, G[andh] will find:

Ga

Gn

Gd

or Gh

G[andh][andh] will find:

Gaa

Gan

Gad

Gah

Gna

Gnn

Gnd

Gnh

Gda

Gdn

Gdd

Gdh

Gha

Ghn

Ghd

or Ghh

And so on. So the point of using G[andh][andh][andh][andh]i is to find every possible four-letter combination of a, n, d, and h. That way, no matter *how* many ways our author has misspelled "Gandhi," we'll catch them all.

In other words, the order of the characters inside the brackets doesn't matter. The strings you suggested--

[andh]

[hand]

[ahnd]

and [anhd]

--are all functionally identical. Each one tells Word to find either an "a," an "n," a "d," or an "h."

Posted in Editing | Leave a comment

Wildcard Combinations

Last week we discussed the basics of using wildcards to find text in a Microsoft Word document. You can read last week's newsletter here:

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

This week we'll talk about how to combine wildcards, which will let you get pretty fancy about the stuff you want to find. Basically, you just need to know that you *can* combine wildcards. Then you can get as crazy as you like.

Last week we used the "?" wildcard to find every three-letter combination starting with b and ending with t--"bet," "but," "bit," "bat," and so on--by searching for "b?t" with "Use Pattern Matching" turned on in the Find dialog box.

Now let's say we wanted to find the same characters but add others as well. For example, we might want to find every three-letter combination starting with b and ending with d--"bed," "bud," "bid," "bad," and so on--in *addition* to the combinations ending in t. Can we really do that? Sure!

After bringing up the Find dialog (Edit > Find) and turning on "Use Pattern Matching," we'll start by entering the letter b into the "Find What" box, telling Microsoft Word to find that letter.

Next, we'll enter the ? wildcard, which tells Microsoft Word to find any single character.

Finally, we'll enter a new wildcard: [td]. Microsoft Word will find any *one* of the characters specified in the brackets.

Altogether, the string of characters looks like this--

b?[td]

--and there we are, doing wildcard combinations! This particular combination tells Microsoft Word to find the letter b followed by any other single character followed by t or d.

How will something like this help you in editing? Suppose you're working on a manuscript in which the author has misspelled a name in nearly every way possible. You could comb through the manuscript over and over, hoping to catch all the variations. Or, you could be *sure* to catch them all by searching with wildcards. For example, let's say your manuscript is a book about India and the name in question is Gandhi. Your author has misspelled it as "Ghandi," "Gahndi," and "Ganhdi." (Not possible? Hah!) You can find every last one of them with the following string:

G[andh][andh][andh][andh]i

Then, if you've put the correct spelling, "Gandhi," in the "Replace With" box, you can find and replace each wrong spelling with the right one in a single pass, which is much more efficient than finding and replacing each variation separately.

You may be wondering why you couldn't just use the * wildcard to represent the whole string of letters, like this:

G*i

You could. But remember, the * wildcard represents *any* string of characters--including spaces. It's not limited to characters within a word (and neither are other wildcards). That means, in addition to finding the misspelled names, it will find the first 14 characters of the following phrase: "Go to the officer's hall." So be careful, especially if you're planning to use "Replace All" rather than finding and replacing one item at a time.

There is a way to simplify the wildcard combination, however. Consider this string:

G[andh]{3}i

It's functionally the same as G[andh][andh][andh][andh]i. The {3} tells Word to find exactly three more occurrences of the previous "expression," which is [andh].

But now a complication: Suppose that our slapdash author has also spelled Gandhi's name as "Gandi." Uh-oh. Our original string won't catch that, because this new misspelling is one character shorter than our string specifies. But consider this:

G[andh]{2,3}i

The {2,3} tells Word to find from 2 to 3 occurrences of the previous expression, so this string will catch all of our misspelled variations so far.

What if we want to allow for more or fewer characters, being particularly unsure of our author? We can use this string:

G[andh]@i

The @ wildcard tells Microsoft Word to find *one or more* occurrences of the previous expression. That ought to cover nearly anything our author throws at us. If we want to get a little more specific, we can use {2,}, which tells Word to look for *at least* two occurrences of the previous expression.

By this time you've probably noticed a pattern to these wildcards, but if not, I'll summarize:

A question mark ? finds any single character.

An asterisk * finds any string of characters.

Square brackets [] specify the characters to find.

Curly braces {} specify how many occurrences of the characters to find.

{n} finds an exact number (such as 2) of the preceding character or expression.

{n,} finds at least n occurrences (such as 3) of the preceding character or expression.

{n,n} finds from n to n occurrences (such as 3 to 5) of the preceding character or expression.

@ finds one or more occurrences of the preceding character or expression.

Here's a parting tip: What would happen if we put a lowercase rather than a capital G at the beginning of our string? Word wouldn't find the misspelled names. Why? Because with "Use Pattern Matching" turned on, Word automatically matches case--a useful thing to know.

That brings us to the subject of finding a range of characters--something we'll talk about next week.

Posted in Editing | Leave a comment