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
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:
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.
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!
When you use Word's Find and Replace capability, clicking the Replace button performs the replacement and automatically ...
Discover MoreIf you need to make replacements in your document, the Find and Replace tool is the go-to option. If you want to replace ...
Discover MoreHTML 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 MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2026 Sharon Parq Associates, Inc.
Comments