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 8, 2017)

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.

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

Deleting a View

When you no longer need a view, you can get rid of it by deleting it. Deleting unnecessary views is a good idea because it ...

Discover More

Listing the Settings in a Template

Templates allow you to define and collect many formatting settings that control how your documents appear. Getting a report ...

Discover More

Changing Vertical Cell Alignment

If you have a large row height, you may want to adjust how the information in a cell is aligned vertically. Sheets allows you ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (menu)

Removing the Box from a Text Box

Insert a text box, and it is automatically formatted to have a border around it. Getting rid of the border is easy, if you ...

Discover More

Hyperlink Formatting

Word, as you type, normally formats hyperlinks automatically. If you don't like the way that hyperlinks look in a particular ...

Discover More

Creating an Inline Heading

When settling on an overall design for your document, you need to decide how you want your headings to appear. If you want ...

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 8Mpixels. 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 7 - 2?

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.