Displaying a Live Word Count

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


1

Word displays, on the status bar, a variety of information that can help you while you are writing. For instance, the status bar shows the number of pages in the document and the line number on the current page. One thing that would be helpful is if the status bar showed the number of words in the document, as you were typing.

Such a feature is not built in to Word, however. The status bar is not reconfigurable via a macro, other than to show or hide the entire bar or write a message to it. Coding a macro that continually wrote a message to the status bar would mean the normal information would not get shown, so a solution that uses the status bar is probably not acceptable.

It is possible to write a macro that would continuously check the word count in a document, and then display the result in another area of the document, such as the title bar or a toolbar button. Depending on the type of system you have, such a solution may not be acceptable; you will need to conduct some tests to see if it is. The internal code to calculate the word count for a document is rather slow, particularly as your documents get larger. This means that constantly checking the word count could slow down your entire system, perhaps to an unacceptable degree.

With this caveat in mind, consider the following set of macros:

Sub AutoExec()
    NumberOfWords
End Sub

Sub NumberOfWords()
    Dim lngWords As Long
    Dim myRange As Range
    With Word.Application
        If .Windows.Count > 0 Then
            Set myRange = ActiveDocument.Content
            lngWords = myRange.ReadabilityStatistics(1).Value
            .Caption = Format(lngWords, "##,##0") & " words - Microsoft Word"
        Else
            .Caption = "Microsoft Word"
        End If
        .OnTime Now + TimeValue(OnTm(lngWords)), "NumberOfWords"
    End With
End Sub

Private Function OnTm(ByVal lngWd As Long) As String
    Select Case lngWd \ 1000
        Case 0 To 10
            OnTm = "00:00:01"
        Case 11 To 20
            OnTm = "00:00:05"
        Case 21 To 30
            OnTm = "00:00:10"
        Case 31 To 40
            OnTm = "00:00:15"
        Case Else
            OnTm = "00:00:20"
    End Select
End Function

There are three macros included in this set, each of which does a different task. The first macro, named AutoExec, will run automatically whenever Word starts. Its only purpose is to call the next macro, NumberOfWords, for the first time.

The NumberOfWords macro is the workhorse of this set. It checks to see if there are any windows open in Word. If so, then it calls Word's internal coding to determine the number of words in the document. It then formats the output and displays it on the title bar for the window. If there are no windows open, then the macro simply displays "Microsoft Word" on the title bar.

The final thing that NumberOfWords does is to tell itself when to run again. It does this by using the OnTime feature of VBA, setting the restart time to be sometime within the next 20 seconds. This is where the third macro, OnTm, comes into play. It takes a look at the number of words in the current document and determines the interval between runnings of the NumberOfWords macro. If there are 10,000 or fewer words in your document, then the macro is run every second. If there are 11,000 to 20,000 words, then it is run every five seconds, and so on. The reason for this checking was covered earlier in this tip: the calculation of the word count and the formatting of the title bar information can take a while (in VBA terminology), and if your document is large, this can cause unwanted and noticeable delays in updating your document. You can, if desired, play with the coding in the OnTm function to determine the best delay breakdown for the types of documents you use.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1608) applies to Microsoft Word 97, 2000, 2002, and 2003.

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

Embedding Fonts in Excel

Unlike some other programs (like Word), Excel doesn't provide a way for you to embed fonts in a workbook. Here's a ...

Discover More

Missing PivotTable Data

Wonder what happened to the data behind a PivotTable? It could be in a number of places, and tracking it down could be a ...

Discover More

Permanently Turning On Set Precision As Displayed

Some people prefer to have what is displayed on the screen in Excel be the precision at which the program works. If you ...

Discover More

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (menu)

Word Count is Zero

If you use the Word Count tool and are surprised that it returns a count of 0, it could be because of what you selected ...

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

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
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 four minus 0?

2021-11-30 21:50:40

Charlie Hoying

This was an awesome tool, but I had a 15,000 word document and my Word began freezing up. Now, every title bar says "Document title - 14 words - Microsoft Word." From your code, it seems that ".caption" represents the title bar of the document? Is there a way to change it to just "Document - Microsoft Word" or simply "Document"?


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.