Word Macro to Count Words Under Each Heading 1
Question details
The user wants to automatically count the words in the section following each Heading 1 and append the total word count to the heading text itself, formatted like 'Heading 1 (255 words)'.
- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Managing document sections and tracking the length of specific chapters or segments within a large Word file.
- Observed behavior
- Microsoft Word does not provide a built-in feature to calculate and append section word counts to headings automatically, requiring a custom VBA macro solution.
Ensure you save your file as a Word Macro-Enabled Document (.docm) and enable the Developer tab in your ribbon before adding or running custom scripts.
Use a VBA Macro to Count Words per Heading
Since Word lacks a native section word counter, you must use the Visual Basic for Applications (VBA) editor to insert a custom script that iterates through your headings.
Writing a macro for this specific task requires identifying the ranges between each 'Heading 1' style and calculating the word count within that range. Because the response team focuses on built-in Word features, you will need to source the exact VBA code from a developer community.
Press ALT + F11 on your keyboard to open the Microsoft Visual Basic for Applications window.
In the VBA window, click 'Insert' from the top menu, then select 'Module' to create a blank script file.
Paste your custom VBA code into the module window. If you do not have the code, request VBA assistance on Stack Overflow using the 'vba' tag, providing your document structure and counting rules.
Press F5 or go to 'Run' > 'Run Sub/UserForm' to execute the code and update the headings in your active document.
Edit Word Documents Easily with WPS Office
If you are looking for a fast, reliable, and free alternative to Microsoft Office, WPS Office is an excellent choice. It handles Word documents seamlessly and provides a powerful suite of editing, formatting, and word-counting tools without the heavy subscription costs.
- 1. Download and Install: Get the free installation package from the official WPS website and follow the on-screen instructions.
- 2. Open Your Document: Launch WPS Writer and seamlessly open your existing Word files with perfect formatting retention.
- 3. Use Built-in Tools: Navigate to the Review tab to access advanced word count and document structuring tools natively.

Frequently Asked Questions
How can I count words in a specific section without a macro?
You can manually select or highlight the text under the heading. The status bar at the bottom left of the Word window will display the word count specifically for the selected text (e.g., '255 of 1,000 words').
How do I enable the Developer tab in Word?
Go to File > Options > Customize Ribbon. In the right pane under 'Main Tabs', check the box next to 'Developer', then click OK. The tab will now appear on your ribbon, granting access to macros and VBA tools.
Why isn't my VBA macro running in Word?
Your macro security settings might be disabling it by default. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings to enable macros. Also, ensure your file is saved as a Word Macro-Enabled Document (.docm).




