
Tips.Net > WordTips Home > Editing > Find and Replace > Selective Formatting in Replacements
Summary: Do you need to replace text with a term or phrase that uses multiple formats? You can perform this seemingly complex task using the powerful find and replace tools in Word, or you can create a macro that will do the trick for you. (This tip works with Microsoft Word 97, Word 2000, Word 2002, and Word 2003.)
Even though you cannot be selective in your searching (previous tip), Word can be much more flexible when it comes to actually replacing information. For instance, let's say you have a document in which you have many instances of the characters X45. If you want to find these characters and replace them with a regular X and a superscripted 45, there are several ways you can go about it.
The first method involves a two-step search and replace. You can follow these general steps:
It doesn't take terribly long to do these two steps, and if you need to do them in multiple documents you can automate the process by recording a little macro that does them.
Another way to approach the problem is to create a little macro that does the actual search and replace in one pass of the document. The macro can find all occurrences of X45, select just the 45 part, make it superscript, and then go on to the next occurrence. The following macro does just that:
Sub DoX45()
Dim oRng As Range
With Selection
.HomeKey unit:=wdStory
With .Find
.ClearFormatting
.Forward = True
.text = "X45"
.Execute
While .Found
Set oRng = ActiveDocument.Range _
(Start:=Selection.Range.Start + 1, _
End:=Selection.Range.End)
oRng.Font.Superscript = True
oRng.Start = oRng.End
.Execute
Wend
End With
End With
End Sub
Finally, if you don't particularly care for macros, there is an even easier solution:
By following these steps, Word replaces all instances of X45 with the contents of the Clipboard, which happens to be the formatted version you want to use. In other words, your text is formatted in one search and replace operation.
Tip #1553 applies to Microsoft Word versions: 97 2000 2002 2003
Take Control! Master the real power behind Word! Successfully master the secrets of powerful formatting and create documents that stand out from the rest. Best of all, you can create documents that are easy to maintain and quick to change.
Check out WordTips: Sytles and Templates today!
Learn to search for and replace text, formatting, graphics, and special characters the easy way with WordTips: Find and Replace. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips