Displaying the Number of Replacements Made

Written by Allen Wyatt (last updated May 2, 2026)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365


8

When manually using Find and Replace, Barry notes that it finishes with a message as to how many replacements were made. He wonders if he can instruct Word to display the same message when doing a Find and Replace in a macro.

The short answer is no, you cannot access the count that is displayed by Word after it does its Find and Replace. There is a workaround, however, that may be usable.

When you normally do a Find and Replace in a macro, you use code similar to this:

With ActiveDocument.Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "old text"
    .Replacement.Text = "new text"
    .Forward = True
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .MatchByte = False
    .MatchFuzzy = False
    .Wrap = wdFindStop
    .Execute Replace:=wdReplaceAll
End With

Upon executing the code, all instances of "old text" are replaced with "new text." However, because it is being run in a macro, Word doesn't display a message, as Barry notes. VBA doesn't allow any access to the number of changes made by the replace operation.

The way around this is to make a slight structural change, in this manner:

lCount = 0
With ActiveDocument.Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "old text"
    .Replacement.Text = "new text"
    .Forward = True
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .MatchByte = False
    .MatchFuzzy = False
    .Wrap = wdFindStop

    Do While .Execute Replace:=wdReplaceOne
        lCount = lCount + 1
    Loop
End With

The key change here is that wdReplaceAll was changed to wdReplaceOne, so VBA makes one change at a time. For each pass through the Do While loop, a single replacement is made and the lCount variable is incremented. When this code is complete, lCount will contain the number of replacements made, which meets Barry's need.

The different approach (wdReplaceOne vs. wdReplaceAll) does come with a tradeoff, however—it is a bit slower. Unless your document is seriously long or has a ton of replacements to be made, the speed difference should be negligible.

Finally, understand that as presented in this tip, the Find and Replace operation affects only the main document content. If you also want the operation to affect content in headers, footers, footnotes, endnotes, and the like, you would need to step through the StoryRange collection to affect everything else. That said, a manual Find and Replace (what Barry is comparing to) also only affects the main document unless you specifically direct Word to affect other document areas.

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 (13979) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365.

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

Concise Directory of Available Symbols

Need to know what the different codes are that you can use with the Alt key, along with the characters resulting from ...

Discover More

Jumping to the Real Last Cell

Jumping to the last cell in a worksheet should be easy, but you may not always get the results that you expect. This tip ...

Discover More

Adding a Printer

One of the most common output devices used with computers is a printer. This tip explains, in detail, how you can set up ...

Discover More

Discover the Power of Microsoft Office This beginner-friendly guide reveals the expert tips and strategies you need to skyrocket your productivity and use Office 365 like a pro. Mastering software like Word, Excel, and PowerPoint is essential to be more efficient and advance your career. Simple lessons guide you through every step, providing the knowledge you need to get started. Check out Microsoft Office 365 For Beginners today!

More WordTips (ribbon)

Replacing without Automatically Finding

When you use Word's Find and Replace capability, clicking the Replace button performs the replacement and automatically ...

Discover More

Finding and Replacing in Headers and Footers

If you need to make replacements in your document, the Find and Replace tool is the go-to option. If you want to replace ...

Discover More

Removing HTML Tags from Text

HTML tags are great when you want to display information on a web page. They are not so great when you have them in a ...

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}] (all 7 characters, in the sequence shown) 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 2 + 6?

2026-05-05 11:26:48

Allen

.MatchFuzzy is used in only some language versions of Word, such as Japanese. I have no idea how it ended up in my original code. You can delete the line entirely (unless you are, of course, using a Japanese version of Word). Setting it to False works, as well, because that means it has no bearing on the actual Replace operation.


2026-05-05 11:20:15

Barry

@ Allen
Just 'solved' my issues an d then read your latest, thank you.

I made the following changes:

.MatchByte = False
.MatchFuzzy = False
'' .Wrap = wdFindStop
.Wrap = wdFindContinue 'changed ...stop to ...continue.

'' Do While .Execute Replace:=wdReplaceOne
Do While .Execute (Replace:=wdReplaceOne) 'added brackets

Now works for me many thanks for your patience.
Curiosity! what does the .MatchFuzzy actually do?


2026-05-05 08:44:54

Allen

Do me a favor, Barry, and take out this line: ".MatchFuzzy = True"

Let me know if it works.


2026-05-05 05:57:22

Barry

I have tried to resolve this error but cannot find it.
A straight Copy and Paste of the first code in the above Tip, and all goes well.
BUT a Copy and Paste of the second code and I immediately get

Do While .Execute Replace:=wdReplaceOne --- in red text; and a Debug/Compile gets the 'Syntax error' message.

The full code copied back from my project:
Sub NewTextOldText()
Dim lCount as Long
lCount = 0
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "old text"
.Replacement.Text = "new text"
.Forward = True
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.MatchByte = False
.MatchFuzzy = False
.Wrap = wdFindStop

Do While .Execute Replace:=wdReplaceOne
lCount = lCount + 1
Loop
End With
End Sub


2026-05-04 09:08:52

Allen

There must be something else going on, Barry, because Do While ... Loop is a construct that should work in all versions of Word VBA. A syntax error may indicate that there is a typo in some part of your code.


2026-05-04 05:09:02

Barry

I got too excited to quickly!!! Saw there was a solution and posted the respose below before trying it out.

I adjusted my own code to include the loop etc and got a syntax error on the Do While ...loop.
Having now copied the complete exaple above, I still get the syntax error on the Do While... loop
Is this because there is no 'while what' definition?
Just setting Do...Loop andd the error goes away, but then the loop seems to be infinite.
Any further help please?


2026-05-03 07:47:29

Barry

Brilliant! Just what I needed. Thanks to both Allen, and Michael.
This may be a bit out of place here?? but...
Congrats to Allen and your wife. Hope the move goes smoothly.


2026-05-02 08:47:02

Barbie

At least in my version, if you look at the status bar as a find-and-replace macro is running, it briefly flashes the number of changes made.


This Site

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

Videos
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.