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

**URL:** <https://boards.straightdope.com/t/word-any-way-to-search-and-replace-with-multiple-formats/457888>\
**Category:** Factual Questions\
**Created:** [July 27, 2008, 1:07am UTC](https://boards.straightdope.com/t/word-any-way-to-search-and-replace-with-multiple-formats/457888 "2008-07-27T01:07:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chorpler](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chorpler/32/2888_2.png) [@chorpler](https://boards.straightdope.com/u/chorpler)\
**Post date:** [July 27, 2008, 1:07am UTC](https://boards.straightdope.com/t/word-any-way-to-search-and-replace-with-multiple-formats/457888/1 "2008-07-27T01:07:50Z")

</div>

A while back I posted [this thread](http://boards.straightdope.com/sdmb/showthread.php?t=469775) 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 …

---

<div class="post-metadata">

**Author:** ![Scarlett67](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/scarlett67/32/7387_2.png) [@Scarlett67](https://boards.straightdope.com/u/Scarlett67)\
**Post date:** [July 27, 2008, 1:28am UTC](https://boards.straightdope.com/t/word-any-way-to-search-and-replace-with-multiple-formats/457888/2 "2008-07-27T01:28:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rhythmdvl](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Rhythmdvl](https://boards.straightdope.com/u/Rhythmdvl)\
**Post date:** [July 27, 2008, 1:32am UTC](https://boards.straightdope.com/t/word-any-way-to-search-and-replace-with-multiple-formats/457888/3 "2008-07-27T01:32:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mike.V](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@Mike.V](https://boards.straightdope.com/u/Mike.V)\
**Post date:** [July 27, 2008, 1:40am UTC](https://boards.straightdope.com/t/word-any-way-to-search-and-replace-with-multiple-formats/457888/4 "2008-07-27T01:40:52Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![chorpler](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chorpler/32/2888_2.png) [@chorpler](https://boards.straightdope.com/u/chorpler)\
**Post date:** [July 27, 2008, 2:10am UTC](https://boards.straightdope.com/t/word-any-way-to-search-and-replace-with-multiple-formats/457888/5 "2008-07-27T02:10:43Z")

</div>

[QUOTE=Scarlett67]  
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.  
[/QUOTE]

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?

---

<div class="post-metadata">

**Author:** ![Scarlett67](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/scarlett67/32/7387_2.png) [@Scarlett67](https://boards.straightdope.com/u/Scarlett67)\
**Post date:** [July 27, 2008, 2:42am UTC](https://boards.straightdope.com/t/word-any-way-to-search-and-replace-with-multiple-formats/457888/6 "2008-07-27T02:42:59Z")

</div>

[QUOTE=chorpler]  
Is there any way to automatically execute a macro until it has scanned through the entire file?  
[/quote]

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.

> [@](#):
>
> 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?

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

---

<div class="post-metadata">

**Author:** ![Scarlett67](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/scarlett67/32/7387_2.png) [@Scarlett67](https://boards.straightdope.com/u/Scarlett67)\
**Post date:** [July 27, 2008, 2:46am UTC](https://boards.straightdope.com/t/word-any-way-to-search-and-replace-with-multiple-formats/457888/7 "2008-07-27T02:46:05Z")

</div>

[QUOTE=Rhythmdvl]  
What about using wildcards? I thought you could exclude text from those.  
[/quote]

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.

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

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.

---

<div class="post-metadata">

**Author:** ![Harriet\_the\_Spry](https://avatars.discourse-cdn.com/v4/letter/h/e56c9b/32.png) [@Harriet\_the\_Spry](https://boards.straightdope.com/u/Harriet_the_Spry)\
**Post date:** [July 27, 2008, 2:53am UTC](https://boards.straightdope.com/t/word-any-way-to-search-and-replace-with-multiple-formats/457888/8 "2008-07-27T02:53:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![elfkin477](https://avatars.discourse-cdn.com/v4/letter/e/a9a28c/32.png) [@elfkin477](https://boards.straightdope.com/u/elfkin477)\
**Post date:** [July 31, 2008, 6:26am UTC](https://boards.straightdope.com/t/word-any-way-to-search-and-replace-with-multiple-formats/457888/9 "2008-07-31T06:26:40Z")

</div>

[QUOTE=chorpler]  
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?  
[/QUOTE]  
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?
