Word: Any way to search and replace with multiple formats?

A while back I posted this thread asking how to invert the italics in several parts of a big file. Now I have a similar question. I’ve run into several instances of a situation like the following:

I put the name of a particular ship, the Sally, in italics. And in numerous places I used the possessive form of the ship, as in “Sally’s sails billowed.” Now I’ve decided I’d rather leave the apostrophe and the “s” un-italicized in those cases. So I thought I’d do a global search-and-replace for Sally’s with Sally’s. Unfortunately, as far as I can tell, you can only apply one format to text to be searched for, and one for the text to be replaced.

I could convert all instances of Sally’s to plain text and then re-italicize the “Sally” part, but there is also an actual character named Sally, and that would italicize all instances of her name and hopelessly mess things up. And I can’t just un-italicize all instances of apostrophe-s because there are some long sections that are entirely in italics where apostrophe-s shows up a lot.

So, does anybody have any helpful tips on how to accomplish this? If only Word let you search for the actual formatting codes like “begin italics” and “end italics” like WordPerfect 5.1 used to let me do …

If we’re just talking about fixing the exact term “Sally’s”, you can record a macro. You’ll want to test the following on a dummy version of your document, as I don’t have time to proof it myself. And I’m assuming you’re not a total Word noob.

  • Place the cursor at the beginning of your document.
  • In Word 2003, Tools > Macro > Record New Macro. Or double-click REC in the status bar. You can assign the macro to a keyboard shortcut if you wish. I often use the name “temp” and the shortcut Ctrl+T for temporary macros.
  • Find “Sally’s”
  • Click Cancel to close the Find dialog.
  • Hit right arrow once to move to the end of the selection.
  • Hold down Shift and hit left arrow twice to select the apostrophe-s.
  • Ctrl+I to toggle the italic to roman. (This assumes that you are certain the selection is indeed italic to begin with. Beware globals!)
  • Hit right arrow once to move to the end of the selection.
  • Click the “Stop macro” button.

Run the macro as many times as you need to fix your problem. This assumes that you have no “Sally’s” referring to your character. If you want to be really careful, you can define two macros, one to find the text, then you can look to see if you want to change it, then another macro to do the change. I leave this as an exercise for the reader.

I think this should work, with my caveat above.

What about using wildcards? I thought you could exclude text from those.

Note: this will NOT work (or at least it won’t in Word 2000) if you have tracked changes on.

Well I don’t know the specifics of Word’s style-dependent search, so I’m not sure how helpful this is, but when I encounter problems like this I find it is often easier to use a “two pass” find and replace.

What I would do is:

  1. Search and replace italic “Sally’s” with italic “Sally!!!'s” (or some other unused character combination)
  2. Search and replace italic “!!!'s” with non-italic “'s”

Hopefully that’s in the right direction…

Good idea – if I search for “Sally’s” italicized, it should find only the ship name versions. Is there any way to automatically execute a macro until it has scanned through the entire file?

Unfortunately that won’t work for all of my similar scenarios. Anybody know if there is any way to do something like “Find italicized space. If the next character is italicized, do nothing; if the next character is normal, de-italicize this space.” using the code in a macro?

Yes, but it involves tinkering with the VBA, and I haven’t gotten that advanced yet with my VBA tinkering. The folks over at the Word-PC list would know. Unfortunately I’m in a time crunch for the next few days, but if I get a few spare minutes I’ll check my books. Googling “visual basic loops” might turn up something, or you could try the Word MVPs site.

Probably, again using some sort of VBA loop, also over my head. I just do this sort of thing manually (find: italicized space; replace: regular font; click Find Next or Replace as needed).

Nope. You can exclude text (for example, “find any character but a space”, but you can’t find mixed formats in a simple S&R.

An important caveat! NEVER do wildcard S&R with Track Changes on. Good point.

Mike V.: Yes, that works well too! Thanks for the reminder.

Are there other italicized 's you need to keep? Could you just replace all italic 's with plain 's?

You can keep adding commands to the marco, if you wish, so you could have it repeat it’s actions a few times to find everything.

A common one I use to rid a document of hard returns goes something like this:
replace ^p^p with ~
replace ^p with space
replace ~ with ^p^p (^p^p are the “real” paragraphs, we need to put them back in)
replace space space with space
replace space space with space <— sometimes there are space space spaces that become space spaces after the first go round, hence the command to look again.

I think something’s not quite right with my example so I don’t recommend trying it specifically, but you get the idea, right?