logo
search
VBA & Macro Problems

How to Count Words in Each Word Paragraph Using a VBA Macro

Natalie TaylorNatalie Taylor Sep 28, 2026 869 views

Question details

The user needs to calculate and display the individual word count for every paragraph in a long document to analyze paragraph length.

How to Count Words in Each Word Paragraph Using a VBA Macro
Product
Word
Device & OS
not provided
Scenario
Reviewing a lengthy document where the writer needs to identify paragraphs that are either too short or excessively long for better pacing and readability.
Observed behavior
Standard word count tools only provide the total document word count or the count for a manual selection, requiring a macro to automate paragraph-by-paragraph statistics.
Before you start

Ensure your document is saved as a Macro-Enabled Document (.docm) and that the Developer tab is enabled in your ribbon before writing or running VBA code.

Solution 1Recommended

Insert Word Count Directly Before Each Paragraph

Use a VBA macro to loop through the document and insert the calculated word count at the beginning of each paragraph for quick inline reviewing.

This method modifies your active document by adding a text string (e.g., '[15 Words]') before the first word of each paragraph. It utilizes the ComputeStatistics(wdStatisticWords) method to ensure accurate counts.

1
Open the VBA Editor

Press ALT + F11 on your keyboard to open the Microsoft Visual Basic for Applications window.

2
Insert a New Module

In the top menu, click 'Insert' and select 'Module' to create a blank workspace for your macro.

3
Input the Macro Code

Write a script that loops through 'ActiveDocument.Paragraphs', calculates the count using 'ComputeStatistics(wdStatisticWords)', and inserts the result using 'Paragraph.Range.InsertBefore'.

4
Run the Macro

Press F5 or click the 'Run' button. The macro will process the document and prepend the word count to each paragraph.

Insert Word Count Directly Before Each Paragraph
Macro Clean-up: You can add a prompt in your VBA code to ask if existing paragraph statistics should be removed before inserting new ones, keeping your document formatting clean.
Use WPS Writer for Macro Support

Easily Run Macros and Count Words with WPS Writer

WPS Writer offers excellent compatibility with VBA macros, allowing you to run custom scripts like paragraph word counters seamlessly. It provides a lightweight, highly compatible, and user-friendly alternative for advanced document editing.

  1. 1. Download and Install WPS Office: Get the latest version of WPS Office from the official website and install it on your computer.
  2. 2. Open Your Document: Launch WPS Writer and open the document you wish to analyze.
  3. 3. Access the Developer Tab: Navigate to the Developer tab on the ribbon and click on 'VBA Editor' to input your paragraph word count macro.
  4. 4. Run the Script: Execute the macro directly within WPS Writer to view the word count statistics for every paragraph.
Fully supports VBA macros to automate complex document formatting and data extraction.Highly compatible with Microsoft Word document formats (.docx, .doc, .docm).Features a built-in, comprehensive word count tool for standard document analysis.Lightweight and fast, ensuring smooth performance even with lengthy, macro-heavy documents.
microsoft office alternative - wps office

Frequently Asked Questions

Can I count words in a specific paragraph without using a macro?

Yes. If you only need to check a few paragraphs, simply highlight the paragraph with your mouse. The status bar at the bottom of the Word window will display the word count specifically for your highlighted selection.

How do I remove the word counts inserted by the macro later?

If your macro inserted the counts as specific text (for example, '[15 Words]'), you can use the Find and Replace feature (Ctrl + H) with wildcards to locate that exact text pattern and replace it with nothing, effectively removing it.

Why is my VBA macro not running in my document?

Macros are often disabled by default for security reasons. You need to go to your Trust Center settings, enable macros, and ensure your file is saved as a Macro-Enabled Document (.docm).