Count Word Find and Replace Changes in Text Boxes and Footnotes
Question details
Count Find and Replace changes across document text, text boxes, and footnotes in Word.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- The user wants one replacement total for selected Word document locations.
- Observed behavior
- Word's Find and Replace does not provide the desired combined count across all document locations.
Open the document in a desktop version of Word that supports VBA, and identify the exact text to find and its replacement. Test the macro on a copy first, because it changes the document as it counts.
Run a VBA macro that counts replacements across selected Word stories
Use this method to replace text and report a combined count for the main document, footnotes, and accessible text-frame stories.
Word organizes document content into separate stories. This macro follows each selected story and its linked story ranges, replacing one match at a time and counting each change.
The example uses Word's standard, case-insensitive Find syntax, not wildcard matching. It excludes headers, footers, endnotes, and other story types. Text in some grouped or specially anchored objects may require separate handling.
In desktop Word, open the document, then select Developer > Visual Basic. If the Developer tab is hidden, enable it in Word's ribbon settings.
In the VBA editor, select the document or its template in the Project pane, then choose Insert > Module.
Paste the code below into the module. Change the findText and replaceText values to the text you want to use; leave replaceText empty if you want to remove the found text. Sub CountStoryReplacements() Dim doc As Document Dim story As Range Dim part As Range Dim searchRange As Range Dim findText As String Dim replaceText As String Dim total As Long findText = "old text" replaceText = "new text" If Len(findText) = 0 Then MsgBox "Enter text to find in the macro." Exit Sub End If Set doc = ActiveDocument For Each story In doc.StoryRanges If story.StoryType = wdMainTextStory Or _ story.StoryType = wdFootnotesStory Or _ story.StoryType = wdTextFrameStory Then Set part = story Do While Not part Is Nothing Set searchRange = part.Duplicate With searchRange.Find .ClearFormatting .Replacement.ClearFormatting .Text = findText .Replacement.Text = replaceText .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False End With Do While searchRange.Find.Execute(Replace:=wdReplaceOne) total = total + 1 searchRange.Collapse Direction:=wdCollapseEnd Loop Set part = part.NextStoryRange Loop End If Next story MsgBox "Total replacements: " & total End Sub
Return to Word, select Developer > Macros, choose CountStoryReplacements, and select Run. Review the total in the message box and spot-check the main text, footnotes, and text boxes.

Edit Word documents with WPS Writer
WPS Office is a free, lightweight alternative with a familiar interface for editing documents. Open compatible Word files in WPS Writer to continue working without a complicated migration; it does not run the Word-specific counting solution on this page.

Frequently Asked Questions
Why does the macro search Word stories?
Word stores the main document, footnotes, and text frames in separate story ranges. The macro uses Document.StoryRanges and NextStoryRange to search the selected locations and combine their counts.
Does the macro include headers and footers?
No. It selects only wdMainTextStory, wdFootnotesStory, and wdTextFrameStory. Header and footer text stories are excluded, although text frames accessible through the selected text-frame story may be searched.
How can I make the search case-sensitive?
In the macro's Find settings, change .MatchCase = False to .MatchCase = True, then run the macro from Developer > Macros.
Can I use the macro to delete matching text?
Yes. Set replaceText = "" in the VBA module, then run CountStoryReplacements. Test it on a copy first and verify the resulting document.




