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

by Allen Wyatt
(last updated February 13, 2017)

13

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

Making Bookmarks Bold

Do you want an easy way to see all the bookmarks in your document? Word provides a way to make them visible, or you can use ...

Discover More

Sheets for Months

One common type of workbook used in offices is one that contains a single worksheet for each month of the year. If you need ...

Discover More

Alt+Enter Stopped Working Correctly

What do you do if a keypress you know worked correctly before all of a sudden stops working as you expect? This tip outlines ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies 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 a ...

Discover More

Counting Words the Old Fashioned Way

One way to specify word count is to count characters and divide by five. If you still need this old-fashioned way of ...

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
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}] 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 8 - 2?

2017-07-27 07:45:39

Lisa Sheppard

Hi Allen

Is there a way to select the 'start' and 'end' point in text that you need to keep an eye on, and have a watch window like you do in Excel to see where you are? I have an MSc dissertation to submit, which also has things I don't need to include in the word count - hence the start/end question!

Kind regards

Lisa


2017-05-03 09:27:39

Peter van den Berg

Thank you all for the tips!
For my thesis I was looking for a solution that displays the wordcount in the active document, per section. As you all found there are no clear-cut solutions, so I took matters in my own hands and programmed one: Its was a bit of a hassle to do so with a random number of sections, but a loop and a variable matrix worked that out fine: It took some time and plenty of googling, as it is my first time coding, so i expect it could be done more easily, but it works exactly as intended!

Sub WordCountPerSectionMacro()
'____________Declare variables
Dim sBookmarkname As String 'Declare variable sBookmarkName
Dim oRng As Word.Range
Dim iNumSec As Integer 'Declare variable iNumSec
Dim iCounter As Integer 'Declare variable iCounter
Dim iTotal As Integer 'Declare variable iTotal
Dim sOutput As String 'Declare variable sOutput
'____________End declare variables

With ActiveDocument 'Apply code within the active document.
sBookmarkname = "Wordcount" 'Fill the variable with the name of the bookmark where the output is to be printed.
If .Bookmarks.Exists(sBookmarkname) = True Then 'If the bookmark existst, continue.

'____________Prepare variables
Set oRng = .Bookmarks(sBookmarkname).Range 'Set objectrange to the range of sBookmarkname.
oRng.Text = "" 'Clear the objectrange (prevent including previous wordcounts in the counter).
iTotal = 0 'set the total wordcount back to 0.
iCounter = 0 'set the counter back to 0.
iNumSec = .Sections.Count 'set iNumSec to the number of sections in the document.
'____________End prepare variables

'____________Start loop
Do Until iCounter = .Sections.Count
iCounter = iCounter + 1
ReDim iWordcount(1 To iNumSec) As Integer 'Declare a range of variables named iWordcount1 untill iWordcount(number of sections in document)
iWordcount(iCounter) = Format(.Sections(iCounter) _
.Range.ComputeStatistics(wdStatisticWords), "0") 'Fill iWordcount(iCounter) with the number of words in that section. (thanks Ameet!)
iTotal = iTotal + iWordcount(iCounter) 'Add the number of words in that section to the total number of words.
sOutput = sOutput & "Section " & iCounter & " has " _
& iWordcount(iCounter) & " Words" & vbCrLf 'Add a line with the current section and wordcount to the output variable
Loop
'____________End loop
Else
MsgBox "Please add a bookmark named " & sBookmarkname 'If the bookmark does not exists, prompt user to create one.
End If

'____________Outputs
oRng.Text = sOutput & "Total wordcount: " & iTotal 'Clear the object range and fill it with the output variable plus the total wordcount
.Bookmarks.Add sBookmarkname, oRng 'Add a new bookmark at location oRng
'____________End outputs
End With
End Sub


Now, i slammed this one flat for readability on this webpage, but i advise you to use the proper indents if you intend to use its functions.


2016-06-29 21:28:45

R. Ambrose Raven

Though very good info, note that Word 2003 has a toolbar for the purpose. Tools > Customise > Word Count


2015-04-24 15:15:42

donna

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 ?


2015-02-13 12:50:02

Rollie

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.


2013-07-04 07:43:43

Ika

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!


2013-01-09 06:42:52

david b

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


2012-12-03 21:49:41

Boon

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.


2012-12-03 21:16:23

Boon

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.


2012-11-15 10:37:31

Erka

Is it possible to count per section but without (foot)notes?


2012-09-06 08:41:14

David

Thanks Ameet. I'll try that


2012-09-05 11:21:24

Ameet

Re: David

Try changing the formula to

sTemp=Format(.Sections(2).Range.ComputeStatistics( wdStatisticWords), "0")


2012-06-21 07:26:32

David

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...


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.

Newest Tips
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.