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

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:

    1. From the Tools menu, choose Options.


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


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


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


  3. From the Tools menu, choose Grammar.


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


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

Additional query words: 1.0 1.1 1.10a 2.0 winword2 winword proofing tools correctext gcs houghton mifflin

Keywords :
Version : WINDOWS:1.0,1.1,1.1a,2.0,2.0a,2.0a-CD,2.0b,2.0c
Platform : WINDOWS
Issue type :


Last Reviewed: December 22, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.