Loading
Word.Tips.Net WordTips (Menu Interface)

Using a Macro to Change the Formatting of All Instances of a Word

Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Using a Macro to Change the Formatting of All Instances of a Word.

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.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1762) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Using a Macro to Change the Formatting of All Instances of a Word.

Related Tips:

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

 

Comments for this tip:

Beth    25 Sep 2014, 19:59
OK. I figured it out. One needs to use .Wrap = wdFindStop instead of .Wrap = wdFindContinue
Beth    25 Sep 2014, 18:44
I have used this same macro (recorded using macro)for years, only recently switching to WORD 2013.

I usually only want to use it within selected text. Sometimes it will do this, but now it won't. It changes all instances within the document.

Do you have any insight into this?
awyatt    15 May 2014, 11:48
David: You need to do a wildcard search. Display the Replace tab of the Find and Replace dialog box (Ctrl+H), then make sure the Use Wildcards check box is selected.

Put this in the Find What box: (\<i\>)(?*)(\</i\>)

Put this in the Replace With box: \2

With the insertion point still in the Replace With box, click Format | Font and set the font to italics.

Click Replace All. All done!
David    15 May 2014, 10:31
Allen,

   Thanks for the help. I'm going to try to work with what you've got here to hone in on what I need. I'm working in Microsoft Word on an old .XML file for an e-book. We're using a new conversion method and I have to go through and remove all the old XML mark ups and replace them with the new ScribeNet mark up (SCML). One of the things I frequently must do is find words between <i> and </i> and italicize the words between these tags, then delete the tags.

    So I understand that this macro shows how to find a certain word, but what I need is for the macro to find <i>, then italicize everything AFTER <i> until it comes to </i>. I'm sure there's a way to do it, but I don't know how. Any suggestions on where I might learn more about how to do this? I don't think CodeCademy.com offers Visual Basic.
Tanya Harvey    06 Feb 2013, 14:42
Thank you for this Allen. I recorded a script for changing several words in italicized copy back to regular. The script simply didn't work because it didn't include what change in format I wanted. I added ".Replacement.Font.Italic = False", based on your sample above, and now it works perfectly. I don't know why the recorder didn't create the correct script, but I'm happy now and learned something new.

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 3+4? (To prevent automated submissions and spam.)
 
          Commenting Terms
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2013)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2013)

Our Products

Premium Newsletters

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2014 Sharon Parq Associates, Inc.