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.

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

by Allen Wyatt
(last updated July 31, 2018)

11

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.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

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.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Creating a Full-Page Border

Borders are easy to add around text or entire paragraphs. It may be surprising to you to learn that Word can just as ...

Discover More

Changing Existing Captions

Word allows you to automatically create captions for various elements of your document, such as figures and tables. These ...

Discover More

ExcelTips: The Macros

Macros provide a way for you to extend the capabilities of Excel. The key to macros is understanding how VBA works. ...

Discover More

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!

More WordTips (menu)

Formatted Merging

When you use the mail-merge capabilities of Word, the information merged takes on the formatting of your source document, ...

Discover More

Copying Formats

Want to copy a format from one place to another without taking your hands off the keyboard? It's easy to do if you apply ...

Discover More

Using Chapter Numbers with Page Numbers

Do you need to add page numbers that include, as well, a chapter number? It's relatively easy to do, as described in this ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven more than 6?

2016-06-20 15:20:54

Peter

the 1 page word format is converted in 2 page, while generated using macro. Can somebody guide me how to handled the word page layout in macro


2016-04-05 22:44:50

Yogesh

Hi
I want to open a word document through excel macros and wants to format opened word document using single click.plz help me


2015-10-26 01:57:45

jason

something got corrupt on my word 2003 file.

i lost all my "heading" 1, 2,3.

Is there a way that i can change all the

Normal + Arial, (Latin) 16 pt, (Latin) Bold

into

"heading 1"

thank you
jason
jsvlad@gmail.com


2015-08-26 22:59:50

priya

Hi,
I need a macro to format the document. MY requirements are:
body text: Font size:10.5, style: Arial
Headings: Font size:11, style: Arial.
Kindly help me in this.


2014-11-05 15:52:50

Paul Hanson

Yes, you can use this macro to replace several words. See my blog for a complete write up as posting as a comment seemed like I was writing too much. http://prhmusic.blogspot.com/2014/11/character-styles-revisited.html


2014-11-03 07:34:45

Rasmus

Hi.
Can I use this macro to make several different words in bold?

Best Regards Rasmus


2014-09-25 19:59:47

Beth

OK. I figured it out. One needs to use .Wrap = wdFindStop instead of .Wrap = wdFindContinue


2014-09-25 18:44:16

Beth

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?


2014-05-15 11:48:45

awyatt

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!


2014-05-15 10:31:57

David

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.


2013-02-06 14:42:46

Tanya Harvey

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.


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.