Loading
Word.Tips.Net WordTips (Menu Interface)

Word Count for a Section

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.

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.

Related Tips:

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!

 

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 5+3 (To prevent automated submissions and spam.)
 
 
           Commenting Terms

Comments for this tip:

R. Ambrose Raven    29 Jun 2016, 21:28
Though very good info, note that Word 2003 has a toolbar for the purpose. Tools > Customise > Word Count
donna    24 Apr 2015, 15:15
is it possible to change (section) to page so that i know how much word in a page live so that everytime i insert a word on a page it show me how many word by pages,. reseting counter at zero ever pages ?
Rollie    13 Feb 2015, 12:50
Is it possible to paste the word count table output at a certain place within the document instead of a MsgBox? This is really helpful, thanks.
Ika    04 Jul 2013, 07:43
I also found the same problem as david b. It appears that the Words.Count function actually counts formatting marks (like paragraphs and even spaces!) as words.

Using "...Range.ComputeStatistics(wdStatisticWords)" insteal (like in Ameet's post) should do the trick.

Great post Allen!
david b    09 Jan 2013, 06:42
This is a very useful feature for the entire document. Sadly the word count for each section seems to be much larger (by 800 words in my case) than when doing it manually. I wonder if this can be fixed? Thanks
Boon    03 Dec 2012, 21:49
OK. Solved. Many thanks. All I needed to do was to cordon off the part I want into a section. Note down which section it is, then arrange to print the word count at a bookmark point. Assign a shortcut to the macro and it's done. The only thing now is that the word count is slightly off when compared to the built-in Word's function. But I can live with that.

Yayy. Many thanks.
Boon    03 Dec 2012, 21:16
I'd like to do a word count for a selection (not a section) and show it at a particular point (which can be bookmarked). Is this possible? This will be very useful when you write an abstract, for example.
Erka    15 Nov 2012, 10:37
Is it possible to count per section but without (foot)notes?
David    06 Sep 2012, 08:41
Thanks Ameet. I'll try that
Ameet    05 Sep 2012, 11:21
Re: David

Try changing the formula to

sTemp=Format(.Sections(2).Range.ComputeStatistics( wdStatisticWords), "0")
David    21 Jun 2012, 07:26
Have just found this - which answers most of my previous question! Still wondering if a Field Formula can relate to a specific selection of text though...
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.