An American Editor

May 15, 2013

The Only Thing We Have to Fear: Wildcard Macros

Whenever I talk to colleagues about macros, it is as if a funereal pall has enclosed us. My colleagues, generally, tell me that they cannot write macros, that it is much too complicated, especially wildcard macros.

If I ask if they ever use Word’s Find & Replace, they all admit that, yes, they do. “Congratulations,” I say, “because each time you use Find & Replace, you have written a macro! You just haven’t recorded it.”

The only thing we have to fear about macros is our fear of macros.

I suppose, technically, Find & Replace is not macro writing, but truly, a macro is just a way to find some sequence and do something to that sequence — be it bold the sequence, highlight it, replace it with another sequence, delete it, whatever.

Most everyone who uses Microsoft Word has recorded a keyboard macro. Word makes doing so very easy. Again, congratulations if you have written a keyboard macro, because you are on your way to macro wizardship.

There is a key to writing macros. It is a secret that macro wizards rarely share, but I’m going to share with you. The secret is wrapped up in a single magical word: analysis. Analysis of what you need a macro to do is the key to writing a macro. Sure you need to have some arcane language (what good is wizardry without arcane language all its own?) and all of the arcane language you need to write the macros can be found in Jack Lyon’s Macro Cookbook for Microsoft Word and in Wildcards in MS Word Macros, which is a compilation of information on wildcards that Jack Lyon wrote for his blog years ago and which you can download for free by clicking the title-link. Alternatively, you can use the Wildcard Find & Replace Macro found in EditTools to “write” the macros for you, but analysis is the real key to writing macros.

Consider this problem: You have a list of 100 references in which the styles are all over the place. Author names are often listed like this:

Arnold, J. H., K. L. Swift, and A.J.H. Archimedes.

but you need the author names to look like this:

Arnold JH, Swift KL, Archimedes AJH:

You can fix the names manually or by using macros. Manually will take nearly forever, so the better method is to use macros. Here is where analysis matters.

When I began using macros, I saw this problem and thought, “How can I write a macro to fix these author names?” My thinking was a single macro to take care of it all. I quickly discovered that a single macro can’t do the job, but a series of macros that can be combined into a single macro could. The key was series of macros, which meant that I needed to break the problem down into solvable (or macroable) parts.

The first part is Arnold, J. H., which I need to change to Arnold JH,. What I need to find is as follows:

  1. any mix of letters of varying length
  2. that is followed by a comma
  3. and a space
  4. a single uppercase letter
  5. followed by a period and a space
  6. a single uppercase letter
  7. followed by a period
  8. and a comma and a space

I need to replace the find list with

  1. the mix of letters found in 1
  2. the space found in 3
  3. the single uppercase letter found in 4
  4. the single uppercase letter found in 6
  5. and the comma and space found in 8

Note that what I no longer need is not included in the list of replace with items (i.e., find items 2, 5, and 7). Also note that, in analyzing what needs to be found, items that I no longer want are listed on their own lines in the find list.

If you are using Word’s Find & Replace dialog with Use Wildcards checked, you would manually enter the following Find string [paired parens represent the information on a single line in the find list, thus, ([A-z]@) represents line 1: any mix of letters of varying length]:

([A-z]@)(,)( )([A-Z]{1,1})(. )([A-Z]{1,1})(.)(, )

And the following Replace string (the backslash+number represents the corresponding find item, e.g., \1 represents line 1: any mix of letters of varying length and \8 represents line 8: a comma and a space):

\1\3\4\6\8

I can hear you groan. But it isn’t as difficult as it appears. All of the information to write the strings is available in the downloadable Wildcards in MS Word Macros document (just click on the link).

If you are using the EditTools’ Wildcard Find & Replace Macro, you click buttons to make your selection and the code is written for you. An added feature with the Wildcard Find & Replace Macro is that you can save this find and replace so that you can reuse it in the future; with Microsoft’s Find & Replace, the strings cannot be saved. However, what I used to do before I created the Wildcard Find & Replace Macro — and recommend that you do — was keep a special Word document with these strings in it so I could copy and paste when needed in the future. I set up the file like this:

1. Change Arnold, J. H., to Arnold JH,
Find: ([A-z]@)(,)( )([A-Z]{1,1})(. )([A-Z]{1,1})(.)(, )
Replace: \1\3\4\6\8

Once you have entered the strings in either Microsoft’s Find & Replace dialog or in the Wildcard Find & Replace Macro, click Replace All and all author names that fit this particular format will be altered. Then move to the next series to analyze, which is to change K. L. Swift, to Swift KL,. In this instance, what I need to find is as follows:

  1. a single uppercase letter
  2. followed by a period and a space
  3. a single uppercase letter
  4. followed by a period
  5. and a space
  6. any mix of letters of varying length
  7. that is followed by a comma
  8. and a space

I need to replace the find list with:

  1. the mix of letters found in 6
  2. the space found in 8
  3. the single uppercase letter found in 1
  4. the single uppercase letter found in 3
  5. the comma found in 7
  6. and the space found in 5

What I no longer need is not included in the list of replace with items (i.e., find items 2 and 4). Also note that, in analyzing what needs to be found, items that I no longer want are listed on their own lines in the find list.

If you are using Word’s Find & Replace dialog with Use Wildcards checked, you would manually enter the following Find string:

([A-Z]{1,1})(. )([A-Z]{1,1})(.)( )([A-z]@)(,)( )

And the following Replace string:

\6\8\1\3\7\5

I said that you can’t save the strings as a macro if you are using Word’s Find and Replace dialog. That is true as far as it goes, but it doesn’t go all that far. There is a way to save the strings as a true macro without using EditTools’ Wildcard Find & Replace Macro. What you do is record a simple Find and Replace macro, for example, find bush and replace it with blues, using Word’s Record Macro feature, and give it a name like WildcardAuthorCorrection1; be sure to keep a list of what that macro does (or will do once you edit it). (If you don’t know how to record a simple macro, the fastest and best way to learn is to use Jack Lyon’s Macro Cookbook for Microsoft Word. Within a few minutes you will be a master at recording simple macros and even at editing them.)

Open the newly recorded macro to edit it, and replace the .Text = bush entry with .Text = [your find string] and replace the .Replacement.Text = blues with .Replacement.Text = [your replace string]. Make sure all the items labeled as True are changed to False except change .MatchWildcards = False to .MatchWildcards = True.

Once you get hooked on macros, the possibilities are endless and you’ll never let go. More importantly, you will improve your editing speed, accuracy, and efficiency, which translates into a higher effective hourly rate and a more profitable editing business.

You’ve got nothing to fear — macros are conquerable!

6 Comments »

  1. Wow. I’m an engineer (sorry, an author who does engineering stuff in daylight hours), have coded perl, C++ (and Fortran, back in the day) and had *no* idea Word was this powerful.

    Thank you VERY much.

    Like

    Comment by Tony McFadden (@Tony_McFadden) — May 15, 2013 @ 5:01 am | Reply

  2. Thanks so much for this! I understand the usefulness and importance of macros, and use some very simple ones, but this explanation that anchors the elements of a macro to its output has made me more confident about incorporating more of them into my editing.

    Like

    Comment by Jocelyn Truitt — December 21, 2013 @ 9:41 pm | Reply

  3. […] The Only Thing We Have to Fear: Wildcard Macros, An American Editor […]

    Like

    Pingback by Computer tools for copy editors: macros » Right Angels and Polo Bears — September 9, 2014 @ 7:02 am | Reply

  4. […] The Only Thing We Have to Fear: Wildcard Macros, An American Editor […]

    Like

    Pingback by Computer tools for copy editors: macros | textbookeditor — September 16, 2014 @ 9:02 am | Reply

  5. […] and, most importantly, make us money. Although we have discussed wildcard macros before (see, e.g., The Only Thing We Have to Fear: Wildcard Macros, The Business of Editing: Wildcard Macros and Money, and Macro Power: Wildcard Find & Replace; […]

    Like

    Pingback by The Business of Editing: Wildcarding for Dollars | An American Editor — February 18, 2015 @ 4:02 am | Reply

  6. Thank you so much! I have Jack Lyon’s “Macro Cookbook,” but something wasn’t clicking. I was so frustrated because I knew these wildcards could help me get through boring, repetitive tasks more quickly, but I just couldn’t get it! Your step-by-step method and the emphasis on analysis got me over the hump. And now I can use the very useful “Macro Cookbook.” Thank you!

    Like

    Comment by lsalak — April 21, 2016 @ 3:13 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: