Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Word Count for a Section.

Word Count for a Section

Written by Allen Wyatt (last updated December 1, 2018)
This tip applies to Word 97, 2000, 2002, and 2003


4

One of the benefits of fields is that you can insert dynamic information within your document. When the field is updated, it is replaced with whatever information is current relative to the field in use. For instance, you can use the NumWords field to insert the number of words in the document. When the field is updated, it is replaced with however many words are then in the document.

If you want to find out the number of words in a section, and have it dynamically placed in a document, then you are out of luck. There is no field that will return this information. You can find it out manually by selecting the text in the section and then choosing the Word Count tool, but that obviously doesn't satisfy the desire to have a value that can be inserted into your document and automatically updated.

This means that you will need to rely on a macro to get the desired word count. If you just want to know the number of words in each section of your document, the following macro can be helpful.

Sub WordCount()
    Dim NumSec As Integer
    Dim S As Integer
    Dim Summary As String

    NumSec = ActiveDocument.Sections.Count
    Summary = "Word Count" & vbCrLf

    For S = 1 To NumSec
        Summary = Summary & "Section " & S & ": " _
          & ActiveDocument.Sections(S).Range.Words.Count _
          & vbCrLf
    Next

    Summary = Summary & "Document: " & _
      ActiveDocument.Range.Words.Count
    MsgBox Summary
End Sub

This simply steps through each section, determines the word count in that section, and displays the summary information in a message box. This does not provide a way to dynamically insert the information in the document, but it does provide an illustration of how you can find the word count of a single section.

A variation on the technique allows you to automatically insert the word count for a specific section at the location of a bookmark within your document. Let's say that you have a bookmarked called "WordCount" that you have defined. This bookmark specifies the place where you want the number of words in the second section of your document. The following macro will determine the word count for the specified section, and then insert the text at the location of the bookmark.

Sub InsertWordCount()
    Dim oRange As Word.Range
    Dim sBookmarkName As String
    Dim sTemp As String

    sBookmarkName = "WordCount"
    With ActiveDocument
        sTemp = Format(.Sections(2).Range.Words.Count, "0")
        Set oRange = .Bookmarks(sBookmarkName).Range
        oRange.Delete
        oRange.InsertAfter Text:=sTemp
        .Bookmarks.Add Name:=sBookmarkName, Range:=oRange
    End With
End Sub

The macro could be easily called from other macros, such as one that runs when the document is opened, saved, or printed. That way the word count would be updated at all the normal times when a field is automatically updated.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (519) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Word Count for a Section.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Printing Only Selected Pages

I often need to print only select pages of a document, rather than the whole thing. Word makes it easy to be judicious in ...

Discover More

Ignoring Smart Quotes when Comparing Text

When comparing two pieces of text, you may find that Word's smart quotes can mess up the comparison. Here's a quick way ...

Discover More

Repeating Table Captions with Modifications

Captions can be a great addition to items in your document such as figures and tables. If you want modifications in those ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (menu)

Ignoring Hyphens in Word Counts

When you instruct Word to tell you how many words are in a document, it treats hyphenated words or phrases as if they are ...

Discover More

Word Count in Multiple Selections

Getting a word count for an entire document is easy. What you may not know is that some versions of Word can also provide ...

Discover More

Displaying a Live Word Count

You can use Word's built in tools to figure out how many words are in your document. If you want a real-time, constantly ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 1 + 1?

2023-06-02 08:09:50

TallyWay

Sub InsertWordCount()
Dim oRange As Word.Range
Dim sBookmarkName As String
Dim sTemp As String

sBookmarkName = "WordCount"
With ActiveDocument
sTemp = Format(.Sections(2).Range.ComputeStatistics(wdStatisticWords), "0")
Set oRange = .Bookmarks(sBookmarkName).Range
oRange.Delete
oRange.InsertAfter Text:=sTemp
.Bookmarks.Add Name:=sBookmarkName, Range:=oRange
End With
End Sub


2019-09-23 23:15:18

Mark

Your macro doesn't give the correct word count in my document. I made a minor change and it now works. I changed .Range.Words.Count to .Range.ComputeStatistics(wdStatisticWords)

Full macro is:
Sub WordCount()
Dim NumSec As Integer
Dim S As Integer
Dim Summary As String

NumSec = ActiveDocument.Sections.Count
Summary = "Word Count" & vbCrLf

For S = 1 To NumSec
Summary = Summary & "Section " & S & ": " _
& ActiveDocument.Sections(S).Range.ComputeStatistics(wdStatisticWords) _
& vbCrLf
Next

Summary = Summary & "Document: " & _
ActiveDocument.Range.ComputeStatistics(wdStatisticWords)
MsgBox Summary
End Sub


2019-08-16 03:48:19

Steel

I wish this was easier to follow for someone with no experience in Visual Basic or MS Word macros


2019-06-21 07:32:39

Curtis

Is there anyway to get the Bookmark Insert to ignore words counted in the headers and footers of the section? I just want to have an automatic word count for the body of the text. Thanks in advance.


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.