VBA & Macro Problems

Count Words Including Footnotes and Endnotes With a Word VBA Macro

Khadija KhanKhadija Khan Nov 25, 2026 868 views

Question details

Update a Word macro so its word total includes the main document, footnotes, and endnotes.

Count Words Including Footnotes and Endnotes With a Word VBA Macro
Product
Microsoft Word
Device & OS
not provided
Scenario
A user wants a VBA macro to report a document's word count with its footnotes and endnotes included.
Observed behavior
The existing macro counts only the main document story, so its total omits words in footnotes and endnotes.
Before you start

Open the document in a version of Microsoft Word that supports VBA macros. Make sure the Developer tab is available, and allow macros only if you trust the document and its code.

Solution 1Recommended

Count the main document, footnote, and endnote story ranges

Use this macro to add the word counts from all three relevant Word story types in the active document.

Word stores the main document, footnotes, and endnotes in separate story ranges. This macro counts those story types and follows any linked ranges; it does not count headers, footers, or text boxes.

1
Open the VBA editor

In Word, select Developer > Visual Basic. If Developer is not visible, enable it through Word's ribbon customization settings.

2
Insert the macro

In the VBA editor, select Insert > Module and paste this code: Sub CountWordsWithNotes() Dim story As Range Dim part As Range Dim total As Long For Each story In ActiveDocument.StoryRanges Select Case story.StoryType Case wdMainTextStory, wdFootnotesStory, wdEndnotesStory Set part = story Do While Not part Is Nothing total = total + part.ComputeStatistics(wdStatisticWords) Set part = part.NextStoryRange Loop End Select Next story MsgBox "Words including footnotes and endnotes: " & total End Sub

3
Run the macro

Return to Word, select Developer > Macros, choose CountWordsWithNotes, and select Run. The total appears in a message box.

4
Compare with Word Count

Select Review > Word Count and enable the option to include footnotes and endnotes. Compare the result with the macro total, keeping in mind that Word's option may also include text boxes, which this macro excludes.

Count the main document, footnote, and endnote story ranges
Scope of the macro: This example counts the active document only. For multiple files, adapt it to open each document and run the same story-range calculation for that document.
Free Microsoft Office alternative

Review Word documents with WPS Writer

WPS Office is a free, lightweight alternative with a familiar interface and support for Word formats, making it easy to move documents between suites. The Word VBA macro fix must be performed in Microsoft Word; check macro compatibility before migrating automated workflows.

Review and edit documents containing footnotes and endnotesCompatible with Microsoft Word DOC and DOCX formatsFamiliar editing interface for a smooth transitionFree and lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Word macro miss footnote and endnote words?

Footnotes and endnotes are stored in separate Word story ranges. A macro that counts only wdMainTextStory does not include wdFootnotesStory or wdEndnotesStory.

How can I check the total manually in Word?

Open Review > Word Count and select the option to include footnotes and endnotes. Depending on the Word version, that option may also include text boxes.

Will the macro work if a document has no footnotes or endnotes?

Yes. The macro loops through the story ranges present in the active document, so absent footnote or endnote stories add nothing to the total.

Does this macro count words in multiple Word files?

No. It uses ActiveDocument. To process multiple files, adapt the code to open each file and calculate its story-range total separately.