Word for Windows: How to Get a Word Count for a Text Selection

Last reviewed: July 30, 1997
Article ID: Q83149
The information in this article applies to:
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c

SUMMARY

Microsoft Word for Windows does not have a built-in command to return the number of words in a selection.

This feature was added to Word version 6.0 for Windows. To count the number of words in a selection in Word 6.0, from the Tools menu select Word Count.

MORE INFORMATION

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Workaround 1

You can use the following macro to return the number of words in a selection.

In Word for Windows version 2.0:

   Sub MAIN
   count = 0
   InsertBookmark .Name = "WordCount"
   Cancel
   CharLeft 1
   n = CmpBookmarks("\Sel", "WordCount")
   While n = 8 Or n = 6
        If Asc(Selection$()) > 47 Then count = count + 1
        WordRight 1
        n = CmpBookmarks("\Sel", "WordCount")
   Wend
   EditGoTo .Destination = "WordCount"
   InsertBookmark .Name = "WordCount", .Delete
   MsgBox "Word Count: " + Str$(count)
   End Sub

In Word for Windows version 6.0:

Sub MAIN
count = 0
   EditBookmark .Name = "WordCount"
   Cancel
   CharLeft 1
   n = CmpBookmarks("\Sel", "WordCount")
   While n = 8 Or n = 6
        If Asc(Selection$()) > 47 Then count = count + 1
        WordRight 1
        n = CmpBookmarks("\Sel", "WordCount")
   Wend
   EditGoTo .Destination = "WordCount"
   EditBookmark .Name = "WordCount", .Delete
   MsgBox "Word Count: " + Str$(count)
End Sub

Note: This macro does not work correctly if the selection contains the document's last paragraph marker.

Workaround 2

In version 2.0 of Word for Windows, you can use the Grammar command from the Tools menu to return the number of words in a selection.

After you run the Grammar command, the Readability Statistics dialog box displays a count of words, characters, paragraphs, and sentences for the selection.

This method does not work in version 6.0 of Word for Windows.

To Obtain a Word Count for a Selection in Word for Windows 2.0

  1. Verify that the Show Readability Statistics After Proofing option is selected:

    a. From the Tools menu, choose Options.

    b. Select the Grammar category in the options dialog box.

    c. Verify that the Show Readability Statistics After Proofing

          check box is selected. (Word selects this option by default.)
    

    Note: If you want to display only a word count, uncheck all options

except the Show Readability Statistics after Proofing option.

  1. Select the paragraph(s) for which you want a word count.

  2. From the Tools menu, choose Grammar.

  3. Allow the Grammar command to perform its check. (It is not necessary to make any of the recommended changes or to continue checking the rest of the document.)

  4. Choose the No button when Word asks if you want to continue checking from the beginning of the document.

The word count appears at the top of the Readability Statistics dialog box when the Grammar command has finished checking your selection.

REFERENCES

"Microsoft Word for Windows User's Guide," version 2.0, page 285-287


KBCategory: kbmacro kbhowto
KBSubcategory:
Additional query words: 1.0 1.1 1.1a 1.0 1.10 1.10a 2.0 2.0a
winword2 winword 2.0a proofing tools correctext gcs houghton mifflin
Version : 1.0 1.10 1.10a 2.0 2.0a 2.0a


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.