Written by Allen Wyatt (last updated May 1, 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.
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!
Sometimes you'll run across the need to replace a very specific sequence of characters in your document. It is for these ...
Discover MoreWhen you use the Find and Replace tool in Word, you may want to include what you searched for in the replacement text. ...
Discover MoreWord includes two different search engines. Which search engine you choose to use will dictate what Word shows as ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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