
Tips.Net > WordTips Home > Formatting > Using a Macro to Change the Formatting of All Instances of a Word
Summary: If you use the formatting of a specific word as a design element in your document, you may be interested in the macro in this tip. It allows you to format all occurrences of a word in a desired manner. (This tip works with Microsoft Word 97, Word 2000, Word 2002, and Word 2003.)
It is not uncommon to use repeating design elements in a document. For instance, you may want all occurrences of a particular word to appear in bold italics, at a certain point size. While you can certainly do the formatting by hand, it is much more efficient to allow a macro to do the work for you. By handling the formatting in this way, you don't need to worry about remembering how the word should appear. This macro, FormatWords, is an example of such a macro.
Sub FormatWords()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Warning!"
.Replacement.Text = ""
.Replacement.Font.Bold = True
.Replacement.Font.Italic = True
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
When you run this macro, it searches for all occurrences of the word Warning (followed by an exclamation point) and changes the formatting on it so the word is bold and italics.
Tip #1762 applies to Microsoft Word versions: 97 2000 2002 2003
Find and Replace Almost Anything! Learn the ins and outs of the powerful search engines available in Word. Learn to search for and replace text, formatting, graphics, and special characters the easy way with WordTips: Find and Replace.
Discover how to use Word's mail merge tool to create your own custom documents in just minutes. Great e-book answers all your questions. (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