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

Changing an Existing Style

Excel allows you to create styles that define how your data looks. At some point you may want to change a style you ...

Discover More

Limiting the Options when Saving as a Copy

Word allows you to save your documents in a wide variety of formats. If you want to limit the formats that are available, ...

Discover More

Lookup Logic: Harnessing Excel's 17 Most Powerful Functions (Table of Contents)

Unlock the full potential of your data with Excel's most powerful functions. Lookup Logic: Harnessing Excel's 17 Most ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2019. Spend more time working and less time trying to figure it all out! Check out Word 2019 For Dummies today!

More WordTips (ribbon)

Finding All Camel-Case Words

If you need to find words that mix uppercase and lowercase characters together, you will appreciate this tip. Here I show ...

Discover More

Using Search Text in the Replacement

When you use the Find and Replace tool in Word, you may want to include what you searched for in the replacement text. ...

Discover More

Keeping a Replace Operation Displayed

The Find and Replace tool is designed to help you find and replace information as quickly as possible. However, you may ...

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 7 + 1?

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.