Lyonizing Word: Assigning Macro Shortcut Keys

by Jack Lyon

I recently had the pleasure of doing an interview for the Chicago Manual of Style “Shop Talk” column. In the interview, I explained how to record a simple macro for transposing characters while editing.

After reading the interview, editor Kristi Hein commented:

Terrific. Next, please discuss the process of choosing a keystroke combination for your macro: not using one of the many you’ve already assigned, making it a combo that’s not too convoluted for the hands (defeating the purpose somewhat), and that you will remember among all the other keystroke combinations you’ve assigned. Therein lies the true art of automating Word effectively and efficiently.

Kristi is right, but wow, that’s a tall order. Let’s look at each requirement separately.

Not using one of the many we’ve already assigned

To not use one of the many keyboard combinations already assigned, we need to know the keystroke combinations we’ve already assigned. Here’s how to do that:

  1. Click CTRL + P to open Word’s “Print” dialog.
  2. Under “Settings,” click the dropdown list that begins with “Print All Pages.”
  3. Under “Document Properties,” click “Key Assignments.” (Also, notice the other things you might want to print, such as styles and AutoText entries.)
  4. Click the “Print” button.

You’ll get a nicely formatted document that shows all of your existing key combinations. The entries will look something like this, with the key combinations on the left and the macro names on the right:

Alt+Ctrl+Shift+S — Normal.NewMacros.ChangeStyleBasedOn
Alt+Ctrl+Shift+I — Normal.NewMacros.CheckIndexCodes
Alt+Ctrl+Shift+C — Normal.NewMacros.FixCodes
Alt+Ctrl+Shift+M — Normal.NewMacros.ParseMetadata

“And how do I assign key combinations to begin with?” you’re wondering. There are (at least) a couple of ways:

When you go to record a new macro (under View > Macro), one of your options is to assign a key combination by pressing the “Keyboard” button:

Using the keyboard option

Using the keyboard option

When you do that, you’ll see the following dialog:

The dialog for entering the key combination

The dialog for entering the key combination

If you were working with an existing macro (editing rather than recording), you’d see any existing key combinations under “Current keys.” To assign a new combination, put your cursor in the box labeled “Press new shortcut key” and, well, press a new shortcut key.

If the new key is already assigned to a macro, you’ll get a “Currently assigned to” message like this:

Currently assigned message

Currently assigned message

That’s handy because it helps you avoid accidentally overwriting a combination that you’ve already assigned (although you can overwrite one on purpose). If you don’t get that message, you’re good to go, and you can click the “Assign” button (on the lower left) and then the “Close” button (on the lower right) and then record the keystrokes that will make up your macro. (When you’re finished recording, click View > Macro > Stop Recording.)

If you want to assign a key combination to an existing macro, things get a little more complicated:

  1. Click “File > Options.”
  2. Click the “Customize Ribbon” button (on the left).
  3. Under “Choose commands from,” select “Macros” (unless you want to use one of Word’s built-in commands, which you can also do).
  4. At the bottom of the dialog, you’ll see “Keyboard shortcuts: Customize.” Click the “Customize” button and proceed as explained above.
Customizing

Customizing

But to continue…

Making it a combo that’s not too convoluted for the hands

This, of course, depends on how many fingers you have (I have ten so far) and how large or small they are, along with your native dexterity. As you can see in the picture above, I’m partial to ALT + CTRL + SHIFT, which I actually find easy to press with my left hand while pressing a letter key with my right. If that’s too convoluted for you, you might try CTRL + SHIFT or CTRL + ALT, both of which are easy to do. ALT + SHIFT is a little more difficult. You can even use plain old CTRL or ALT with another character, but that starts to encroach on Word’s built-in key combinations (like CTRL + S to save a document).

There’s another system, however, that you may not know about:

  1. Press your desired key combination.
  2. Press another key.

The result will be something like this:

Two-step key

Two-step key

See that ,”1” after the “Alt+Ctrl+Shift+M”? That means I’ve just created a two-step key combination. To run the macro, I press ALT+CTRL+SHIFT+M. Then I press 1 (the one key, all by itself). At that point (and not before), the macro will run. Pretty slick!

What that means is that you can assign all kinds of two-step combinations (letters will work as well as numbers), which gives you two characters for the mnemonic you use to remember what a combination does. That’s twice as good as one! (Unfortunately, Word won’t let you use more than two.) It also means you can create shortcuts like these:

ALT+CTRL+SHIFT+H,1 (to apply the Heading 1 style)ALT+CTRL+SHIFT+H,2 (to apply the Heading 2 style)

Or these:

CTRL + SHIFT + T,C (to transpose characters)
CTRL + SHIFT + T,W (to transpose words)
CTRL + SHIFT + T,S (to transpose sentences)
CTRL + SHIFT + T,P (to transpose paragraphs)

And so on. The mind reels at the possibilities!

Making it a combo that you will remember among all the other keystroke combinations you’ve assigned

Using two-step combinations should help with that requirement as well, but for serious keyboard junkies there’s another solution — XKeys. The company manufactures various models, from 24 keys on up to 128 keys! You can assign the keys to your macros, label the keys, color code them, and so on. The 60-key model looks like this:

The 60-key XKeys

The 60-key XKeys

Rich Adin swears by this gadget, and he’s one of the most productive copyeditors I know. Maybe you’d find it useful too.

We've met the requirements

In summary, we’ve figured out some ways to meet all of Kristi Hein’s requirements for key combinations:

  • Not using one of the many you’ve already assigned.
  • Making it a combo that’s not too convoluted for the hands.
  • Making it a combo that you will remember among all the other keystroke combinations you’ve assigned.

These may seem like small things, but small things add up to greater editing efficiency, and that means more money in your pocket and less time at work, both of which are big things. I hope this essay will help you achieve them.

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.

Lyonizing Word: From Easy to Impossible — Three Variations on a Theme

by Jack Lyon

Rich Adin just keeps on escalating the difficulty of his requests. That’s okay, because I appreciate a good challenge. Here’s his latest:

Okay, Jack, you solved the problem of reducing the number of authors from more than three down to three.

To see what Rich is talking about, please see my previous posts here: Lyonizing Word: We Can Do This the Easy Way, or . . . and Lyonizing Word: The Easy Way, Not So Easy.

Rich continues:

But there is a caveat: the list of names needs to end with “et al:”. So let me pose three more variations.

Three?! Oh, all right. Here we go:

Variation 1

How do I handle instances where the ending is punctuation other than “et al:”? For example, it could be a different punctuation mark than the colon or it could end with an author name and not “et al” (e.g., “Lyon J, Adin R, Carter TO, Jackson TT, Doe J, Smith K, Winger W:” or “Lyon J, Adin R, Carter TO, Jackson TT, Doe J, Smith K, Winger W, Hoffnagle TTP.”)

How do we handle instances where the ending is punctuation other than “et al:”? Here are Rich’s examples, all laid out for our inspection:

Lyon J, Adin R, Carter TO, Jackson TT, Doe J, Smith K, Winger W:

Lyon J, Adin R, Carter TO, Jackson TT, Doe J, Smith K, Winger W, Hoffnagle TTP.

As usual, the key is to find the “handle,” the unique elements we can grab to carry out our search. (For more on this, please see my article “What’s Your Handle?” [2003] at the Editorium Update.)

In Rich’s examples, the “handles” would have to be the colon that ends the first entry and the period that ends the second. Let’s try modifying the wildcard string from the previous post for Lyonizing Word:

([!^013]@, [!^013]@, [!^013]@, )[!^013]@([:.])

Here’s what that means:

Find any characters except a carriage return: [!^013]
repeated any number of times: @
followed by a comma
followed by a space
repeated three times
and enclosed in parentheses to form a “group.”
Then find any character except a carriage return: [!^013]
repeated any number of times: @
followed by [:.] (specifying a colon or a period) in parentheses to form a group.

And we can use the following in the “Replace With” box:

12

Here’s what that means:

Replace everything that was found
with the text represented by group 1: 1
followed by the text represented by group 2: 2

But does that actually work? Well, sort of, Here’s what we get:

Lyon J, Adin R, Carter TO, :
Lyon J, Adin R, Carter TO, .

Maybe that’s close enough, as it would now be an easy matter to search for comma space colon and replace it with a colon, and to search for comma space period and replace it with a period. But if we want to refine our search string even further, we could use this:

([!^013]@, [!^013]@, [!^013]@), [!^013]@([:.])

Here, we’ve placed the comma and space following the third name outside the parenthetical group, so they’re not included when the group is replaced by /1. That actually solves the problem, if you want to get precise, giving us a result like this:

Lyon J, Adin R, Carter TO:
Lyon J, Adin R, Carter TO.

Variation 2

Rich wrote:

How can I revise the string to work even if there is no consistency in punctuation of names? For example, suppose the names are: “Lyon, J, Adin R, Carter T.O., Jackson TT, Doe, J.; Smith K; Winger, W; Hoffnagle TTP.”

As given, this can’t be done. Why? Because we’ve lost the uniqueness of the comma “handles” that separate the names. For example, instead of this —

Lyon J,

— we have this:

Lyon, J,

And instead of this —

Smith K,

— we have this:

Smith K;

So again, as given, we can’t fulfill Rich’s request. But can we change the “as given”? Why, yes, we can!

We can search for a lowercase letter followed by a comma (at the end of a last name) and replace it with just the lowercase letter (and no comma):

Find what: ([a-z]),
Replace with: 1

We can search for a semicolon (which sometimes follows initials) and replace it with a comma:

Find what: ;
Replace with: ,

Then we can use the same wildcard string we used earlier to fulfill Rich’s request:

Find what: ([!^013]@, [!^013]@, [!^013]@), [!^013]@([:.])
Replace with: 12

You may be wondering if these wildcard strings will affect the article titles and journal names and not just the author names. The answer is, it depends. I’m assuming, for example, that the article titles and journal names don’t include commas (just for purposes of illustration). But if they do, you may have to get creative. Let’s take this as an example:

Levy, D, Ehret G, Rice K, Verwoert G, Launer L, Dehghan A, Glazer N, Morrison A, Johnson A, Aspelund T, Ganesh S, Chasman D: Genome-wide association study of blood pressure, stress, and hypertension. Nature 2009, 41(6): 677-687.

See that comma after “Levy”? Above, we got rid of it with the following strings:

Find what: ([a-z]),
Replace with: 1

But notice that this will also remove the commas after “pressure” and “stress” in the article title, which we don’t want to do. The solution, again, comes down to handles. What do we have that sets off the article title and journal name? In this example, they’re preceded by the colon after the author names (“Chasman D:”) and followed by a carriage return (at the end of the citation). So here’s a rather sneaky solution: Search for a colon followed by anything that isn’t a carriage return until you come to a carriage return. Then replace whatever was found with itself (^&) formatted as Hidden:

Find what: :[!^013]@^013
Replace with (use Hidden formatting): ^&

If you don’t know how to replace using formatting, here’s the secret:

1. Put your cursor in the “Replace with” box.
2. Click the “More” button if it’s showing.
3. Click the “Format” button on the bottom left.
4. Click “Font.”
5. Put a check in box labeled “Hidden.”
6. Click the “OK” button.

Notice that you can replace with all kinds of formatting: styles, paragraph alignment, and so on. You can also use formatting in the “Find what” box! This is really powerful stuff, and if you didn’t know about it before, now you can add it to your bag of tricks.

At any rate, with the article titles and journal names formatted as Hidden, you can make sure they actually are hidden by clicking the “Show/Hide” button (with the pilcrow icon: ¶) on Word’s “Home” tab. Then run your find and replace to remove commas from last names:

Find what: ([a-z]),
Replace with: 1

Finally, unhide the article titles and journal names (after using “Show/Hide” to display them):

Find what: (Hidden formatting)
Replace with: (Not Hidden formatting)

At that point, the commas will be gone from the authors’ last names but preserved in the article titles and journal names.

By the way, if you’re working on a Macintosh, you’ll find that Word doesn’t recognize the standard code for a carriage return (^013) while searching with wildcards. But never fear: you can still do what you need by “escaping” the code with a backslash and treating it as a range using square brackets. In other words, use this:

[ˆ013]

To specify not a carriage return, use the following:

[!ˆ013]

Variation 3

Rich wrote:

How can I adapt the wildcard string to delete those in excess of a certain number? For example, I have one client who wants up to ten author names listed and “et al” used only for names eleven and following. I would like to specify how many names I want retained and replace the excess with “et al.” For example, if there are fifteen names, delete the last five if ten are okay and replace them with “et al.”

Theoretically, we could do that as long as there’s a “handle” that marks the end of the names. Let’s take this example:

Levy D, Ehret G, Rice K, Verwoert G, Launer L, Dehghan A, Glazer N, Morrison A, Johnson A, Aspelund T, Ganesh S, Chasman D: Genome-wide association study of blood pressure and hypertension. Nature 2009, 41(6): 677-687.

There are actually twelve names there, so we want to keep the first ten and replace the last two with “et al.” What’s our handle? The colon after the last name (“Chasman D:”) and before the article’s title. So let’s try an expansion of the wildcard search string we used in the previous post for Lyonizing Word. Instead of grouping three comma-separated names, we’ll group ten:

Find what: ([!^013]@, [!^013]@, [!^013]@, [!^013]@, [!^013]@, [!^013]@, [!^013]@, [!^013]@, [!^013]@, [!^013]@,)[!^013]@(:)
Replace with: 1 et al.2

That would work if Word could handle it. But if you try it, Word will complain: “The Find What text contains a Pattern Match expression which is too complex.” So now what? Honestly, I’m not sure. I tried several other possibilities, none of which were successful. So if you, Gentle Reader, have any ideas about how to accomplish this seemingly impossible feat, I’d love to hear them.

Wildcard searching can’t do everything, but it can do an awful lot. As I’ve said before, after all these years of editing, wildcard searching is the tool I rely on the most. I encourage you to invest the time needed to learn to use this tool, which will repay your efforts many times over. A good place to start is my free paper “Advanced Find and Replace in Microsoft Word.”

I hope you’ll also watch for my forthcoming Wildcard Cookbook for Microsoft Word. I’m still trying to find more real-life examples for the book, so if you have some particularly sticky problems that might be solved using a wildcard search, I hope you’ll send them my way. Maybe I can save you some work and at the same time figure out solutions that will help others in the future. Thanks for your help!

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.

For other Lyonizing Word essays at An American Editor, Lyonizing Word at AAE.

Lyonizing Word: The Easy Way, Not So Easy

by Jack Lyon

After publishing my last article, Lyonizing Word: We Can Do This the Easy Way, or . . ., Rich Adin, An American Editor, wrote:

As written, your wildcard find and replace reduces four names to three if “et al:” is the ending characteristic. How do you write it so that it can handle any number of names, say up to seven?

Good question, and a nice challenge for a wildcard search. Let’s say we have citations with strings of names like this:

Lyon J, Adin R, Carter TO, Jackson TT, Doe J, Smith K, Winger W, et al: blah blah blah

That’s seven names, but let’s see if we can make a wildcard string that will find any number of names and cut them down to three. My first impression is that this might be difficult or even impossible. But let’s try the following wildcard string:

([!^013]@, ){3}([!^013]@, ){1,}(et al:)

Here’s what that means:

Find any character except a carriage return: [!^013]
repeated any number of times: @
followed by a comma
followed by a space
and enclosed in parentheses to form a “group.”
Do that three times in a row: {3}
Find using the same group: ([!^013]@, )
if it occurs once or more (as indicated by the comma): {1,}
followed by “et al:” in parentheses to form a group.

There’s just one problem: It doesn’t work. And that’s how it often is with wildcards — sometimes you have to fiddle around to get the result you want; trial and error are key. So let’s see if we can find just three instances of text using our group:

([!^013]@, ){3}

That doesn’t work either. What in the world is going on here? Let’s try using the group three times in a row:

([!^013]@, )([!^013]@, )([!^013]@, )

That does work. So why not this?

([!^013]@, ){3}

Could it be that {3} doesn’t apply to the wildcard pattern ([!^013]@, ) itself but to the first instance of text that pattern finds? In other words, would that wildcard string  find the first three names in a citation like the following?

Lyon J, Lyon J, Lyon J, Lyon J, Lyon J, Lyon J, Lyon J, et al: blah blah blah

Sure enough, that works! So we’ve just learned something new about wildcard searches. For clarity, I’ll restate it here:

Specifying how many times to find something (using {3}, for example) doesn’t apply to the wildcard pattern it follows but to the first instance of text that pattern finds.

Unfortunately, that means we need to work out a different approach to our original problem. How about this?

([!^013]@, [!^013]@, [!^013]@, )([!^013]@, ){1,}(et al:)

Here’s what that means:

Find any character except a carriage return: [!^013]
repeated any number of times: @
followed by a comma
followed by a space
repeated three times
and enclosed in parentheses to form a “group.”
Find using the same group: ([!^013]@, )
if it occurs once or more (as indicated by the comma): {1,}
followed by “et al:” in parentheses to form a group.

But no, that doesn’t work either! Why not? Oh, yeah, because of that {1,}. As we discovered earlier:

Specifying how many times to find something (using {3}, for example) doesn’t apply to the wildcard pattern it follows but to the first instance of text that pattern finds.

Well, okay, then. We’ll stop using numbers (such as {1,}) to specify how many times a pattern should be repeated (at least for our current purposes). Let’s try this instead:

([!^013]@, [!^013]@, [!^013]@, )[!^013]@(et al:)

Here’s what that means:

Find any characters except a carriage return: [!^013]
repeated any number of times: @
followed by a comma
followed by a space
repeated three times
and enclosed in parentheses to form a “group.”
Then find any character except a carriage return: [!^013]
repeated any number of times: @
followed by “et al:” in parentheses to form a group.

Well, son of a gun; that actually works. So now we can use the following in the “Replace With” box:

12

Here’s what that means:

Replace everything that was found
with the text represented by group 1: 1
followed by the text represented by group 2: 2

Group 1, you’ll remember, was this:

([!^013]@, [!^013]@, [!^013]@, )

It finds the first three names in our citations. And group 2 was this:

(et al:)

It finds the end of our citations.

And so, finally, we’ve succeeded in fulfilling Rich’s original request:

As written, your wildcard find and replace reduces four names to three if “et al:” is the ending characteristic. How do you write it so that it can handle any number of names, say up to seven?

Sometimes the easy way isn’t so easy. Nevertheless, it’s almost always worth pursuing. In Rich’s case, it reduced his editing time from hours (removing extraneous names by hand) to minutes (removing the names with a wildcard find and replace). It also gave Rich a wildcard search that he can save in his fabulous EditTools software for use with future projects. And it provided a deeper and clearer understanding of how to use wildcard searches.

After all these years of editing, wildcard searching is the tool I rely on the most. I encourage you to invest the time needed to learn to use this tool, which will repay your efforts many times over. A good place to start is my free paper “Advanced Find and Replace in Microsoft Word.”

I hope you’ll also watch for my forthcoming Wildcard Cookbook for Microsoft Word. I’m still trying to find more real-life examples for the book, so if you have some particularly sticky problems that might be solved using a wildcard search, I hope you’ll send them my way. Maybe I can save you some work and at the same time figure out solutions that will help others in the future. Thanks for your help!

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.


 

Looking for a Deal?

You can buy EditTools in a package with PerfectIt and Editor's Toolkit at a special savings of $78 off the price if bought individually. To purchase the package at the special deal price, click Editor's Toolkit Ultimate.

Lyonizing Word: We Can Do This the Easy Way, or . . .

We Can Do This the Easy Way,
or We Can Do This the Hard Way

by Jack Lyon

American Editor Rich Adin called me recently with a puzzle. He was editing a list of citations that looked like this:

Lyon J, Adin R, Poole L, Brenner E, et al: blah blah blah.

But his client wanted the citations to look like this:

Lyon J, Adin R, Poole L, et al: blah blah blah.

In other words, many of the citations included one author name too many; the client wanted a limit of three rather than four. And there were hundreds of citations. Rich really didn’t want to remove the superfluous names by hand; it would have taken hours to do, and hours are money. And so, Rich queried, “Is there a way to remove the fourth name automatically?”

There’s nearly always a way. Rich had already tried using a wildcard search, but without success. Microsoft Word kept telling him, “The Find What pattern contains a Pattern Match expression which is too complex.”

The Too-Complex Find What

I’m not sure what wildcard search Rich tried to use, but it might have looked like this:

Find what:

([A-Z][a-z]@ [A-Z], )([A-Z][a-z]@ [A-Z], )([A-Z][a-z]@ [A-Z], )([A-Z][a-z]@ [A-Z], )(et al:)

Replace with:

1235

That’s definitely too complex for Word to handle. Here’s what it means:

Find a capital letter ([A-Z])
followed by a lowercase letter ([a-z])
repeated any number of times (@)
followed by a space
followed by a capital letter ([A-Z])
followed by a comma
followed by a space
with all of that in parentheses to form a “group.”

All of that is repeated three more times, then followed by “et al:” in parentheses to form a group.

The “Replace with” string tells Word to replace what it finds with the contents of groups 1, 2, 3, and 5 — in other words, with the first three names followed by “et al:”.

What’s the Handle?

If Word could handle it, that should work. But Word can’t handle it, so we’ll need to simplify. So we ask ourselves, “What, besides letters, do all of the names have in common?” In other words, “What’s the handle? What can we grab onto?” Well, that’s easy — each name is followed by a comma and a space. That’s our handle!

(For more on this, please see my article "What’s Your Handle?" (2003) at the Editorium Update.)

The Find That Works

The handle means we can simplify our wildcard search string to something like this:

Find what:

([!^013]@, [!^013]@, [!^013]@, )[!^013]@, (et al:)

Replace with:

12

Here’s what that means:

Find any characters except a carriage return ([!^013])
repeated any number of times (@)
followed by a comma
followed by a space
with all of that repeated three times
and enclosed in parentheses to form a “group.”
Then it’s repeated one more time, ungrouped
and followed by “et al:” in parentheses to form a group.

The “Replace with” string tells Word to replace what it finds with the contents of groups 1 and 2 — in other words, with the first three names (group 1) followed by “et al:” (group 2). The fourth name is simply ignored.

To Group or Not to Group Using Parens

Rich ran the new find and replace, then replied, “Thanks, Jack, that works like a charm. Why isn’t the second ‘group’ grouped, that is, in parentheses? I thought that was necessary.”

I replied, “No, it’s not necessary. You group only the items that you want to reference (by 1, 2, etc.) in the ‘Replace with’ box. You could group the other item, in which case you would use ‘13’ in the ‘Replace with’ box. But there’s no need to do so.”

Note that this method of finding the names offers another advantage. Not only will it find names that look like this:

Lyon J,

it will also find names that look like this:

Lyon JM,

or even this:

Lyon JMQ

It will even find names like this:

Thaler-Carter Ruth,

or this:

Harrison G.B.H.,

In fact, it will find anything (except a carriage return) followed by a comma and a space.

Why the Carriage Return?

“Why,” you may be wondering, “specify anything but a carriage return? Why not specify letters instead?” Well, we could have done that, using something like this:

Find what:

([A-z ]@, [A-z ]@, [A-z ]@, )[A-z ]@, (et al:)

Replace with:

12

That means:

any capital or lowercase letter or space ([A-z ])
repeated any number of times (@)
followed by a comma
followed by a space
And so on.

Such a wildcard string would find names like this:

Lyon J,

but not this:

Thaler-Carter R,

Yes, we could add a hyphen to our string, but then we start to wonder about other characters we might need to include, and then things get complicated again. And besides, it’s true that we don’t want to include carriage returns in our search, so it makes sense to exclude them. If we tried to simplify too far, we might use this:

Find what:

(*, *, *, )*, (et al:)

Replace with:

12

The problem with using the asterisk wildcard (*) is that it finds any character any number of times, including tabs, spaces, carriage returns, and everything else you can think of. Sometimes that’s useful, but more often it just leads to confusion. We want to keep things simple but not too simple.

Why Wildcard

To return to our original problem: Rich could have removed all those extra names one at a time, by hand, which is doing it the hard way and eats into the profit line — remember that time is money. Microsoft Word includes powerful tools for doing things the easy way, so why not learn them and use them? If you’ve read this far, you’re doing that, so congratulations.

If you’d like to learn more about how to use wildcard searches, you can download my free paper “Advanced Find and Replace in Microsoft Word.” Working through the paper requires some thought and effort, but the payoff is huge.

Coming Soon

I hope you’ll watch for my forthcoming Wildcard Cookbook for Microsoft Word. I’m still trying to find more real-life examples for the book, so if you have some particularly sticky problems that might be solved using a wildcard search, I hope you’ll send them my way. Maybe I can save you some work and at the same time figure out solutions that will help others in the future. Thanks for your help!

For EditTools Users

If you are a user of EditTools, you can manually create the find and replace strings in the Wildcard Find & Replace macro and then save the macro for future use. However, to do so you need to enter the Find string slightly differently:

Find Field #1: [!^013]@, [!^013]@, [!^013]@,
Find Field #2: [!^013]@,
Find Field #3: et al:

Note that you omit the parens for grouping because EditTools automatically inserts them, which means that you break the string into its group components. (IMPORTANT: Be sure to include in Find Fields 1 and 2 the ending space, i.e., the space following the final comma, which is not visible above.)

Because EditTools treats each of the three fields as a group, your Replace string is:

Replace Field #1: 1
Replace Field #2: 3

After manually entering the information in each of the fields, click Add to WFR Dataset and save this macro for future use. Next time you need it, just click Retrieve from WFR Dataset, retrieve this string, and run it. That is one of the advantages to using EditTools' Wildcard Find & Replace — you can write a wildcard macro once and reuse it as many times as you need without having to recreate the macro each time.

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.

Looking for a Deal?

You can buy EditTools in a package with PerfectIt and Editor's Toolkit at a special savings of $78 off the price if bought individually. To purchase the package at the special deal price, click Editor's Toolkit Ultimate.

 

Lyonizing Word: Shifting Styles

Shifting Styles

by Jack Lyon

In its undying efforts to be “helpful,” Microsoft Word can cause no end of problems. Among the worst of these are what I call “shifting styles,” which can change the formatting of your document without your consent and sometimes without your knowledge. Yow! I know of five ways this can happen. Here’s how to identify and fix each one.

Automatically Update Document Styles

The Problem

You go through your document, fine-tuning its style formatting to the peak of perfection. Then you carefully save your document for posterity. A week later, you reopen your document. What the…? All of your styles have shifted back to their original formatting. You’ll have to do all of that work over again! And how can you be sure it will stick?

The Solution

  1. Open the document.
  2. Click the Developer tab. (If you don’t have such a tab, click File > Options > Customize Ribbon. In the big window on the right, put a check in the box labeled “Developer. Then click the OK button.)
  3. Click the Document Template icon.
  4. Remove that dadburned checkmark in the box labeled “Automatically update document styles.”
  5. Resave your document.

The next time you open the document, your exquisite style formatting will remain intact.

So what’s the point of the “Automatically update document styles” feature? Well, let’s say that your boss just loves to tinker with the look of your company’s forms and stationery, mandating Helvetica one week and Comic Sans the next. If you turn on “Automatically update document styles” for every company document you create, changing the formatting is a snap. Just open the template on which the documents are based, modify the styles, and resave the template. The next time you open one of those documents, its styles will automatically update to match those of the template.

It’s a slick feature, as long as you know when — and when not — to use it.

Automatically Update Styles

The Problem

You’ve just opened a new document from a client, and you italicize the first paragraph, which is a short quotation introducing the chapter. But suddenly all of the chapter text is italicized. What in the world is going on?

You’ve just bumped into Word’s “Automatically update” feature for styles. (This feature affects only the styles in the current document, making it different from the “Automatically update document styles” feature discussed above.) If you don’t know about the “Automatically update” feature, you can spend hours trying to adjust formatting, only to have everything in sight messed up beyond belief.

The Solution

  1. Click the Home tab.
  2. In the Styles section of the Ribbon, right-click the style (such as Heading 1) applied to your text. (If you can’t see the style, click the little gray button under the Change Styles icon to open the Styles task pane.)
  3. Click Modify.
  4. Near the bottom right of the dialog, remove the checkmark from the box labeled “Automatically update.”
  5. Click the “OK” button.

Now when you modify some formatting in your document, you’ll change only the local selection and not everything that’s formatted in the same style. But really, you should avoid using directly applied formatting anyway. Using paragraph and character styles is much more efficient — the True Way — and avoids a multitude of problems.

So what’s the point of the “Automatically update” feature? It allows you to modify styles without drilling down, down, down through multiple menus. Well hey, that’s good! It means you can change formatting directly, see the result immediately, and have the styles updated automatically to reflect that formatting. Pretty neat!

So here’s my recommendation:

  • If you’re designing a document, use the “Automatically update” feature with a bunch of junk text to set your styles exactly the way you want them (be sure to select the whole paragraph before changing the format). Once you’ve got them set, turn off “Automatically update.” Then copy the styles to your real document, or save the junk document as a template that you attach to your real document.
  • If you’re writing or editing a document, make sure the “Automatically update” feature is turned off.

Styles Based on Styles

The Problem

You’re working away, editing a client’s document, and decide to modify the Heading 1 style to use a Goudy typeface. Whoa! Now the Heading 2 and Heading 3 styles are in Goudy as well. What’s going on here?

What’s going on is that your client has made the Heading 2 and Heading 3 styles “based on” the Heading 1 style. If you don’t know how this works, you’ll be scratching your head over the changing formats. If you do know how it works, you can use it to ensure consistent formatting throughout a document.

The Solution

If you don’t want your style to be based on another style, do this:

  1. Click the Home tab.
  2. In the Styles section of the Ribbon, right-click the style (such as Heading 1) applied to your text. (If you can’t see the style, click the little gray button under the Change Styles icon to open the Styles task pane.)
  3. Click Modify.
  4. In the “Style based on” dropdown list, select “no style” (the first option in the list).
  5. Click the OK button.

Problem solved.

But not so fast. Actually, this feature can be quite useful, as long as you know what’s going on.

Let’s say you want all of your headings to be set in Baskerville. It’s true that you could go through and set Heading 1, Heading 2, Heading 3, Heading 4, Heading 5, Heading 6, Heading 7, Heading 8, and Heading 9 (whew!) all to use that font (in varying point sizes, say). But now what if you want to switch to Palatino? Do you really have to go through and modify all of those styles again? Not if you originally based them all on Heading 1. If you did that, all you have to do is change the font for Heading 1, and all of your other heading styles will change as well. Pretty neat! Here’s how to do it:

  1. Click the Home tab.
  2. In the Styles section of the Ribbon, right-click the style (such as Heading 2) applied to your text. (If you can’t see the style, click the little gray button under the Change Styles icon to open the Styles task pane.)
  3. Click Modify.
  4. In the “Style based on” dropdown list, click the style (Heading 1, for example) on which you want to base the current style.
  5. Click the OK button.

Now, whenever you modify the “parent” style (Heading 1), the “child” style (Heading 2) will be modified automatically.

Please note, however, that any changes you make to the “child” style will override the attributes inherited from the “parent” style. For example, if Heading 1 is set to 18 points, you can still modify Heading 2 (based on Heading 1) as 14 points. If you do that, though, you may wonder how to get rid of the override if you need to. Here’s the secret: change the attribute in Heading 2 back to the way it’s set in Heading 1 (14 points back to 18 points). The “child” style will simply pick up its attributes from the “parent style” once again.

You can use this feature to set up whole families of styles that are based on a “parent” style. For example, you might want to set up a family of heading styles, a family of body text styles, and a family of list styles, and then store them all in a special template. Just be sure to use a naming convention that makes it easy to remember which styles are the “parents.” The easiest way to do this may be to use “1” to designate “parent” styles: Heading 1, Body Text 1, List 1, and so on. Then you can use other numbers (2, 3, 4) to indicate “child” styles.

AutoFormat Headings

The Problem

You’re typing along, and suddenly the short line you entered a couple of paragraphs earlier has turned big and bold. Who does it think it is, anyway? When you investigate, you discover that the line has somehow been formatted with Word’s Heading 1 style.

You’ve just discovered one of the wonders of Word’s AutoFormat feature, which should be firmly beaten into submission before it takes over your whole document.

The Solution

  1. Click File > Options > Proofing.
  2. Click the button labeled “AutoCorrect Options.”
  3. Click the tab labeled “AutoFormat As You Type.”
  4. Under “Apply as you type,” remove the check from the box labeled “Built-in Heading Styles.”
  5. Click the OK button.
  6. Click the next OK button.

Now if you type a line of text ending in a carriage return but without ending punctuation (which, by the way, seems to be the defining factor here), Word will no longer see it as a heading and will no longer try to format it as such.

Define Styles Based on Your Formatting

The Problem

As explained above, you’ve turned off the AutoFormat option to apply headings as you type, but you still get automatic formatting. If that’s the case, you may still have the last “AutoFormat As You Type” option turned on. It’s labeled “Define styles based on your formatting,” and Microsoft explains its function like this: “Create new paragraph styles based on the manual formatting you apply in your documents. You can apply these styles in your document to save time and to give your documents a consistent ‘look.’”

The idea that Word is creating new styles as I work just gives me the heebie-jeebies.

The Solution

  1. Click File > Options > Proofing.
  2. Click the button labeled “AutoCorrect Options.”
  3. Click the tab labeled “AutoFormat As You Type.”
  4. Under “Apply as you type,” remove the check from the box labeled “Define styles based on your formatting.”
  5. Click the OK button.
  6. Click the next OK button.

Problem solved — no more proliferation of unwanted styles.

The whole issue with all of these problems is one of control. How much “help” do you want Microsoft Word to give you? If you’re editing, your answer may be “none,” because editors need to have complete control over what’s happening, and they can’t have Word introducing changes they may not even be aware of. When I’m editing, I disable all of these features. If you’ve been suffering from the madness of shifting styles, maybe you’ll want to do the same.

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.

Lyonizing Word: The Right Tool for the Job

The Right Tool for the Job

by Jack Lyon

The sardine fork. The oyster ladle. The cake breaker. The butter pick. Those persnickety Victorians had a utensil for everything! You’ll find some interesting examples here:

Was all of that really necessary? I still eat the occasional sardine, and an ordinary table fork gets the job done. But I’m willing to bet that if I ever tried an actual sardine fork, I’d immediately realize the advantages of doing so. If I ever needed to ladle out oysters, I’ll bet an oyster ladle would be the perfect tool for the job.

The Wrong Tools

Every editor I know uses Microsoft Word. It’s the standard solution, the default program, the accepted tool for word processing. But is it the best tool for editing? Out of the box, it’s not. It has too many features that editors don’t need, and they’re always getting in the way.

When you’re editing, how often do you use SmartArt? How about WordArt? Page color? No? Then why not get rid of them? Why not turn Word into a lean, mean, editing machine? You can do this by customizing Word’s Ribbon. To do so, click File > Options > Customize Ribbon.

On the right side of your screen, you’ll now see a list of the Ribbon tabs and groups, like this:

Jack Lyon Graphic 1

Notice that I’ve unchecked the “Mailings tab.” I don’t want it showing because it’s something I never use. (Note: If you use macros, you should probably keep the “Developer” tab; it allows access to those macros and also allows you to load various document templates that may include macros.)

Now see that dropdown list at the top of the window? The one that says “Main Tabs”? Click it and select “All Tabs.” Now you’ll have many more options to uncheck:

Jack Lyon Graphic 2

Do you really need Chart Tools? Drawing Tools? Picture Tools? If not, make them go away. (Don’t worry—if necessary, you can always get them back again.)

So far, we’ve been removing whole groups of features at once, but you can also remove individual items from a group—if they are items you’ve previously added. Unfortunately Microsoft won’t let you remove the individual default features they think you need to have.

The Right Tools

The other problem with Microsoft Word is that it doesn’t have enough of the tools that editors need—at least not by default. Here again, the solution is to customize the Ribbon. Again, click File > Options > Customize Ribbon. This time, look at the window on the left. In the top dropdown box, select “Commands Not in the Ribbon.” Very interesting!

Jack Lyon Graphic 3

These are Word’s “hidden” commands, the features I encouraged you to explore in my previous article “Let’s Go Spelunking!”

Using the buttons in the window, you can add these features to the groups of your choice on Word’s Ribbon. You can even add your own custom tabs and groups by clicking the buttons labeled “New Tab” and “New Group.” How about adding a tab called something like “Editing Tools,” with all of the features you need for editing? If you’re also a writer, you could add a tab called “Writing Tools.” Some of the features would be different; some of the features would be the same. There’s nothing wrong with having certain features duplicated between tabs or groups, if that makes your work easier.

You can select other features by clicking the dropdown list and selecting “All Commands.” You can even select macros and add them to the Ribbon.

Add-In Tools

Unfortunately, even with the wealth of features that Word provides, there are other editing tools that Word doesn’t provide. For example, how often do you need to transpose two words? Two characters? How much time do you spend lowercasing articles and prepositions in titles? How often do you have to reach for the mouse in order to apply a style?

This is where add-in programs come in. “What’s an add-in program?” you ask. An add-in program is a Microsoft Word template that includes custom macros, Ribbon items, and keyboard shortcuts created specifically for a particular task—kind of like those Victorian utensils. As the name suggests, an add-in isn’t an independent piece of software; it actually works inside Microsoft Word, adding new features that then seem to be an integral part of Word. This isn’t some kind of hack, by the way; Microsoft Word was designed to support such add-ins, which is what makes them possible.

I’m partial to my own add-ins, of course, the ones I sell on the Editorium website. I’m really an editor, not a programmer, and I created these add-ins to make my own work easier. But I think you might like them too.

One of my favorites is the “Cap Title Case” feature in Editor’s ToolKit. When I’m working on a manuscript and come across a title like “The Ghost In The Machine,” or worse, “THE GHOST IN THE MACHINE,” I select the title and press the F5 function key (which activates the “Cap Title Case” feature). Like magic, the title is now capped like this: “The Ghost in the Machine.”

If I want to transpose two words, I put my cursor anywhere in the second word and press the F11 key. To transpose two characters, I press F12. Rather than reaching for the mouse to apply a style, I press F5, which puts all of the styles at my fingertips. And as they say on television, there’s much, much more!

All of these are small things, but those small things add up to big savings in time. And when you’re editing for a living, time is money.

So how much is an add-in actually worth? If it saves you an hour on a single project, it’s probably paid for itself. On the next project, it pays for itself again. And on and on, into the future. Seldom does such a small investment reap such big rewards.

Yes, this is a sales pitch, but I genuinely want you to succeed. That’s why I promote other add-ins like Rich Adin’s EditTools and Daniel Heuman’s PerfectIt.

These tools can make a real difference in how efficiently you work and how much money you can make. With that in mind, why not get them all, at a very special price?

Don’t think of these tools as an expense; think of them as an investment. Then the next time you need an editing tool, you’ll have it—and it will be the right tool for the job. Instead of dishing out tomato slices with a fork, you can use a tomato spoon! Instead of picking up bacon with your fingers, you can use a bacon fork! Using the right tool for the job makes all the difference in the world.

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.

Lyonizing Word: Finding and Replacing Upper- and Lowercase

Finding and Replacing Upper- and Lowercase

by Jack Lyon

Rich Adin, the proprietor of this blog, recently sent me an interesting question. He wrote:

I need a wildcard find and replace, assuming it can be done by wildcards, that searches for the following

Abrams: alpha
booby: alarm

and replaces it with

Abrams: Alpha
booby: Alarm

That is, the first letter after the colon and space is changed from lowercase to uppercase. I know I can do this by macro, and I have one that will do it, but I would like to do it by wildcard so I can make it part of a script I run.

Unfortunately, there's no good way to do that. Using a wildcard search, we can find any lowercase letter (preceded by a colon and space) by using the following string in the Find What box:

: [a-z]

But in the Replace With box, we should use—what? We can't use the following string because it doesn't specify what the replacement letter should be:

: [A-Z]

In fact, if we try that, Word will simply replace what was found with the string itself, giving us this:

Abrams: [A-Z]lpha
booby: [A-Z]larm

There is, however, a rather sneaky (but ultimately unsatisfactory) workaround. We can replace the lowercase letter with itself formatted as uppercase. Here's how:

1. Press CTRL + H to bring up Word's Replace dialog.
2. If the More button is available, click it.
3. Put a check in the box labeled "Use Wildcards."
4. In the Find What box, enter this:

: [a-z]

5. In the Replace With box, enter this

^&

That's the magic code that tells Word to replace what was found with what was found. In other words, if Word finds ": a" it should replace it with ": a" (the same thing it was searching for). You'll see why in just a minute.

6. Make sure your cursor is in the Replace With box.
7. Click the Format button at the bottom left of the Replace dialog.
8. Click Font.
9. Put a check in the box labeled "All caps."
10. Click OK.
11. Click "Replace All."

That should do the trick; all of our lowercase letters following a colon and space are now formatted as "All caps." The reason I said earlier that this is "ultimately unsatisfactory" is that those letters are not actually uppercase; they merely look as if they're uppercase because of their formatting.

In some situations, that may be good enough. But if your document is destined to be published in a format other than Microsoft Word, it may not be good enough, as formatting may change and, like Cinderella at the stroke of midnight, our "uppercase" letters may revert to their true lowercase selves. (How often do we get to use a fairytale allusion in technical writing?)

The only real solution is to use a macro, like this one:

Sub ReplaceLowercaseWithCaps()
Selection.HomeKey Unit:=wdStory 'Position cursor at top of document
Selection.Find.ClearFormatting 'Clear any
Selection.Find.Replacement.ClearFormatting
With Selection.Find

.Text = ": [a-z]" 'Search for colon and space followed by lowercase letter
.Replacement.Text = "" 'Leave empty--the macro will replace the text later
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True 'Specify a wildcard search

End With
Selection.Find.Execute 'Execute the search
While Selection.Find.Found 'While the search is successful

Selection = UCase(Selection) 'Uppercase what was found
Selection.MoveRight 'Move out of the selection
Selection.Find.Execute 'Try, try again

Wend 'End the "While" loop
End Sub

I've added comments to explain what's going on, but the really pertinent line is this one:

Selection = UCase(Selection) 'Uppercase what was found

When Word finds a colon and space followed by a lowercase letter, it selects the colon, space, and letter (naturally, because it found them), so those are the "Selection." The macro then converts those characters to uppercase using the "UCase" function; it sets the Selection as the uppercased version of the Selection, if you see what I mean.

After that, the macro moves to the right so the text is no longer selected. Then it again executes the Find in an effort to locate the next instance of colon, space, and lowercase letter, if one exists.

And yes, for the sake of simplicity, the colon and space are uppercased here as well as the letter. What's an uppercased colon? A colon. What's an uppercased space? A space. If we wanted to, we could modify the macro to handle each of those separately, but why bother when the result is the same? Virtue in simplicity.

Note that we could do the inverse of this, if we needed to, finding any uppercase letter and lowercasing it. To do so, we'd use ": [A-Z]" for the search string, and we'd modify Selection with the LCase function rather than UCase.

I wish that Microsoft had included a better way to handle this. Even though Microsoft didn't, we now have a way to accomplish what we need to do.

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.

________

How to Add Macro to Word & to the QAT

Here’s how to put this macro (or any other) 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.”
  2. Click the “View” tab on Microsoft Word’s ribbon.
  3. Click the “Macros” button.
  4. Type a name for the macro in the “Macro name” box — probably the name used after the first “Sub.” For this macro, that’s “ReplaceLowercaseWithCaps.”
  5. Click the “Create” button.
  6. Delete the “Sub [macro name]” and “End Sub” lines that Word created in the macro window. The macro window should now be completely empty (unless you already have other macros in there).
  7. Paste the macro text at the current insertion point.
  8. Click “File,” then “Close and Return to Microsoft Word.”

To actually use the macro:

  1. Place your cursor at the beginning of your document.
  2. Click the “View” tab on Microsoft Word’s ribbon.
  3. Click the “Macros” button.
  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.)

Here’s how to put the macro on Word’s QAT (Quick Access Toolbar):

  1. Locate the QAT (it’s probably on the top left of your screen either above or below Word’s Ribbon interface).
  2. Right-click the QAT.
  3. Click “Customize Quick Access Toolbar.”
  4. Under “Choose commands from:” click the dropdown list and select “Macros.”
  5. Find and select your macro in the list on the left.
  6. Click the “Add” button to add it to the QAT.
  7. Click the “OK” button to finish.

Lyonizing Word: Formatting with Macros

Formatting with Macros

by Jack Lyon

Most users of Microsoft Word format text by selecting a paragraph and then applying a font. More advanced users apply a style. Here’s why:

  1. Styles are easier to use than direct formatting. Once you have the style set up (with, say, 12-point Arial bold, condensed by 1 point, left justified, with 24 points of leading above and 12 points of leading below), you can apply that style with a single click. But if you apply the same formatting without using a style, you’ll have to make a dozen clicks for each heading. If your document has 50 headings, that’s hundreds of clicks—versus 50 clicks if you use a style.
  2. If you need to change the formatting of, say, level-2 headings, you can simply modify the style rather than tediously selecting each heading and applying a different font. Modify the style, and the formatting of all those headings is automatically changed.

But there is a way to handle formatting that is even more powerful—by using macros.

Suppose that you’ve dutifully applied styles to the various parts of a document, but then your client asks you to change the font—everywhere in the document—from Times New Roman to Adobe Garamond. (No, you should not just select the whole document and apply Adobe Garamond. Why? Because that simply “paints over” the real formatting that is still there in the styles, and it will almost certainly lead to inconsistent formatting somewhere down the line.) You could manually modify each style, but if there are dozens of styles in use, there is a better way. That way is a macro, like this one:

Sub SetFontInAllStyles()
Dim aStyle As Style
For Each aStyle In ActiveDocument.Style
aStyle.Font.Name = "Adobe Garamond"
Next
End Sub

Well, that was easy. Let’s look at each line of the macro (excluding the first and last lines, which simply define the beginning and end of the macro).

Dim aStyle As Style

This line defines (dimensions) a variable, aStyle (which name I just made up), as a style. At one point as the macro runs, aStyle might represent the style Heading 1. At another point it might represent Heading 3. But it will always represent a style.

For Each aStyle In ActiveDocument.Styles

Here's where things start to get interesting. That line tells the macro to cycle through each style (represented by aStyle) in all of the styles in the active document (the document in which your cursor is currently sitting).

aStyle.Font.Name = "Adobe Garamond"

And that line tells Word to set the font for the style currently being represented by aStyle to be Adobe Garamond.

Next

The “Next” line tells Word to go to the next style in the document.

When you run the macro, it will cycle through each style in the document (For Each…) and set Adobe Garamond as the font used in that style.

But what if you want to change the font only in heading styles (Heading 1, Heading 2, and so on)? Try this:

Dim aStyle As Style
For Each aStyle In ActiveDocument.Styles
If InStr(aStyle.NameLocal, "Heading") Then aStyle.Font.Name = "Adobe Garamond"
Next
End Sub

Here's the line of interest:

If InStr(aStyle.NameLocal, "Heading") Then aStyle.Font.Name = "Adobe Garamond"

That line uses a macro command we haven't seen before, InStr, which checks for specific text in a larger string of text. In this case, it checks to see if the text “Heading” appears in the name of the style (for example, “Heading 4”). If it does, then the macro sets the font for the Heading style as Adobe Garamond.

Armed with that little beauty, you can pull off all kinds of formatting marvels. Here are just a few of the options available:

If InStr(aStyle.NameLocal, "Heading") Then aStyle.Font.Bold = True

If InStr(aStyle.NameLocal, "Heading") Then aStyle.ParagraphFormat.Alignment = wdAlignParagraphCenter

If InStr(aStyle.NameLocal, "Heading") Then aStyle.NoSpaceBetweenParagraphsOfSameStyle = True

You can even specify the exact name of the style (rather than using InStr):

If aStyle.NameLocal = "Normal" Then aStyle.ParagraphFormat.Alignment = wdAlignParagraphJustify

If aStyle.NameLocal = "Heading 3" Then aStyle.Font.Italic = True

All of Word’s formatting options are at your disposal.

So yes, if you’re formatting a Word document, you should always use styles. But if you need to modify styles en masse, now you know how.

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.

________

How to Add Macro to Word & to the QAT

Here’s how to put this macro (or any other) 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.”
  2. Click the “View” tab on Microsoft Word’s ribbon.
  3. Click the “Macros” button.
  4. Type a name for the macro in the “Macro name” box — probably the name used after the first “Sub.” For this macro, that’s “______________.”
  5. Click the “Create” button.
  6. Delete the “Sub [macro name]” and “End Sub” lines that Word created in the macro window. The macro window should now be completely empty (unless you already have other macros in there).
  7. Paste the macro text at the current insertion point.
  8. Click “File,” then “Close and Return to Microsoft Word.”

To actually use the macro:

  1. Place your cursor ___________________.
  2. Click the “View” tab on Microsoft Word’s ribbon.
  3. Click the “Macros” button.
  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.)

Here’s how to put the macro on Word’s QAT (Quick Access Toolbar):

  1. Locate the QAT (it’s probably on the top left of your screen either above or below Word’s Ribbon interface).
  2. Right-click the QAT.
  3. Click “Customize Quick Access Toolbar.”
  4. Under “Choose commands from:” click the dropdown list and select “Macros.”
  5. Find and select your macro in the list on the left.
  6. Click the “Add” button to add it to the QAT.
  7. Click the “OK” button to finish.

Lyonizing Word: Deleting Extraneous Carriage Returns in Footnotes and Endnotes

Deleting Extraneous Carriage Returns
in Footnotes and Endnotes

by Jack Lyon

During my editing career, I've often run into problems with footnotes and endnotes in Microsoft Word. Many authors have no clue about how notes are meant to work, and Microsoft certainly hasn't made it obvious. In fact, they've made it easy to mess notes up beyond repair.

One mistake authors make is to insert extraneous carriage returns before or after a note. Why? Because they don't like the positioning of the note on the page, which they're trying to make "pretty," not understanding the problems that will cause in editing and typesetting.

You can try to remove the extraneous returns like this:

1. Click View > Draft.
2. Click References > Show Notes.

Your cursor should now be in the Notes pane.

3. Click Home > Replace.
4. In the "Find What" box, enter two paragraph codes:

^p^p

5. In the "Replace With" box, enter one paragraph code:

^p

 6. Click the "Replace All" button.

Word will replace some of the double returns, but not all of them. And if you try to delete some of the remaining returns, you'll get an error message:

"This is not a valid action for footnotes."

What's going on there is that not all carriage returns are created equal. Some of the returns are "special" note returns, and the only way to delete them is to delete the note itself back in the text.

The solution? A macro, of course. But a macro with a twist. As we've seen, the macro can't just find double returns and replace them with a single return. And trying to delete extra returns results in an error. So let's use that error!

Before running the macro, you must be in Draft view, with your cursor at the top of the Notes pane. (How to get there is explained above.)

In the macro, you'll see a couple of "comments," which are explanations or instructions intended for the person reading the code. Comments are preceded by a single quotation mark ('), which tells the macro to ignore the rest of the text on that line. For example, the first comment in the macro reads:

'To clean returns in endnotes rather than footnotes, change ".Footnotes" to ".Endnotes" in the following line:

And now, here's the macro:

Sub CleanReturnsInNotes()
'To clean returns in endnotes rather than footnotes, change ".Footnotes" to ".Endnotes" in the following line:
NoteCount = ActiveDocument.Footnotes.Count
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find

.Text = "^p^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False

End With
Selection.Find.Execute
On Error GoTo TrapTheError
While Selection.Find.Found

Selection.MoveLeft
'The following line may trigger an error!
Selection.Delete
Selection.Find.Execute

Wend
GoTo TheEnd
TrapTheError:

ErrorCount = ErrorCount + 1
Selection.MoveRight
Selection.Delete
If ErrorCount < NoteCount Then Resume Next

TheEnd:
End Sub

Let's look at some of those lines.

NoteCount = ActiveDocument.Footnotes.Count

NoteCount is a variable; that is, it's a container that can hold a numerical value—in this case, the number of footnotes in the document. We get that value with the VBA command ActiveDocument.Footnotes.Count.

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

Just to be safe, these lines clear any formatting that might already be applied to the "Find What" and "Replace With" boxes in Word's find and replace feature.

The following lines, from

With Selection.Find

down to

Selection.Find.Execute

simply find any instances of double paragraph returns. The replacement text is set to nothing, as we're not trying to replace those returns with anything:

 .Replacement.Text = ""

Instead, we're going to try to delete the second return, which (unless the notes are really messed up) is a regular return rather than a special note return:

 Selection.MoveRight
Selection.Delete

If it's a special note return, then trying to delete it will cause an error, and the macro will execute this line—

On Error GoTo TrapTheError

—which sends the macro to this line:

TrapTheError:

Here's what happens next:

ErrorCount = ErrorCount + 1

Using the variable ErrorCount, we count the number of errors, adding 1 each time we find one. (ErrorCount is initially empty, or zero.)

Selection.MoveRight
Selection.Delete

We move right and delete the next return.

 If ErrorCount < NoteCount Then Resume Next

If the number of errors is less than the number of notes, we're not through yet, as one of the remaining notes may still have a bad return next to it. So, we tell the macro to Resume operation at the next command after the error occurred. That command is:

Selection.Find.Execute

In other words, Word looks for the next occurrence of a double return. And this construction—

While Selection.Find.Found

Selection.MoveLeft
'The following line may trigger an error!
Selection.Delete
Selection.Find.Execute

Wend

—ensures that it will keep looking as long as (While) double returns are found. ("Wend" is short for "While End"—it marks the end of the While construction.)

GoTo TheEnd

When no more double returns are found, this line is executed. It exists simply to avoid executing the error trap (TrapTheError and the following lines) after the macro is finished, at which point

TheEnd:

marks the end of the whole operation.

I hope this explanation has helped you understand better how macros work, and in particular how you can actually use Word errors to force Word to do what you want it to do—something that gives me great pleasure.

Even if you don't understand everything that's going on in this macro, you can still use it to clean up extraneous returns in notes—something that should make your editorial life a little bit easier.

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.

Lyonizing Word: The Next Character Macro

Today’s column by Jack Lyon marks the first essay in a new monthly series, “Lyonizing Word.” In this series, Jack will discuss using Microsoft Word, especially macros, to best advantage during the editing process. Please welcome Jack as a new columnist for An American Editor.

______________

Lyonizing Word: The Next Character Macro

by Jack Lyon

Macros and mastering Microsoft Word are keys to success in the business of editing. One can be a great editor and not master either, but it is more difficult, if not near-impossible, to have a successful editing business if you aren’t master of the tools you use.

My plan is to help you master Word and Word macros. My hope is that you will learn from each of my columns and will take the lessons learned and build on them yourself — for example, by building more complex and more useful macros that fulfill a need in your editing business. Here’s my first installment, which I hope you’ll find useful.

The NextCharacter Macro

I often use character codes while finding and replacing in Microsoft Word. What’s a character code? Here are some common ones:

^09 is a tab
^13 is a carriage return
^32 is a space

Especially in a wildcard search, you may have to use such codes because Word’s wildcard search engine can’t handle certain characters and will give you an error message if you try to use them.

But what if you don’t know the code for the character you need? You can probably look it up online or in a computer book, but wouldn’t it be nice to have a macro that would tell you immediately? Just put your cursor in front of the character and run the macro to get the code number. Here’s a macro that will do just that:

Sub NextCharacter()
Dim NextChar As String
NextChar = Str(AscW(Selection))
MsgBox “The code for the next character is” & NextChar
End Sub

That’s pretty simple, but there’s still a lot going on. Let’s look at each line in the macro.

Sub NextCharacter()

Here we tell Word the name of the macro, which is a subroutine (Sub) named NextCharacter. You can use pretty much any name you like, as long as it doesn’t start with a number or include any spaces. And the parentheses at the end of the name? I’ll reserve that discussion for a future article.

Dim NextChar As String

I just made up the name NextChar but not the commands around it, all of which are part of VBA (Visual Basic for Applications), Microsoft’s programming language for Word and other programs in the Office suite. If you want to learn more about “Dim,” “As,” “String,” and other VBA commands, here’s a good place to start: Getting Started with VBA in Word 2010.

In this line, we’re “dimensioning” (Dim) a variable to hold a value (NextChar) that we’ll use later in the macro. A variable is just a placeholder that can hold a value, like X in your high-school algebra class. Dimensioning just tells Word what *kind* of value we’re using — in this case, a string of characters rather than, say an integer, which can only hold numbers.

NextChar = Str(AscW(Selection))

This assigns a value to the NextChar variable. What value? The one produced by this:

Str(AscW(Selection))

“Selection” is the character to the right of your cursor (in the Western world).

“AscW” tells Word to find the ASCII or Unicode value of that character.

“Str” turns that value into a string — that is, characters rather than a value. Why? So we can see those characters in the message box produced by the next line:

MsgBox “The code for the next character is” & NextChar

This displays a message box (MsgBox) that gives us the code for the next character (as stored in NextChar), preceded by the text “The code for the next character is” just to pretty things up.

End Sub

This line simply ends the macro, or subroutine.

Now, here’s how to put this macro (or any other) 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.”
  2. Click the “View” tab on Microsoft Word’s ribbon.
  3. Click the “Macros” button.
  4. Type a name for the macro in the “Macro name” box — probably the name used after the first “Sub.” For this macro, that’s “NextCharacter.”
  5. Click the “Create” button.
  6. Delete the “Sub [macro name]” and “End Sub” lines that Word created in the macro window. The macro window should now be completely empty (unless you already have other macros in there).
  7. Paste the macro text at the current insertion point.
  8. Click “File,” then “Close and Return to Microsoft Word.”

To actually use the macro:

  1. Place your cursor directly in front of the character you want to identify.
  2. Click the “View” tab on Microsoft Word’s ribbon.
  3. Click the “Macros” button.
  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.)

After the macro runs, a dialog box will appear with the numeric code for the character. To dismiss the dialog box, click OK.

Now that you know the code for the character after your cursor, you can use that code in Word’s Find dialog. Or you can insert it into your document. To do so, hold down the ALT key and enter the code on the numeric keypad. For example, the code for an uppercase A is 65. You could insert that character by holding down the ALT key and entering 65 on the numeric keypad. Of course, it’s a lot easier just to hold down SHIFT and hit the A key, but what if you need to enter something more esoteric? Microsoft provides a code chart here: ANSI Character Codes Chart.

That’s it! I hope you find the macro useful, and that my explanation here helps you understand a little more about how macros work.

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.