Microsoft KB Archive/83149

{|
 * width="100%"|

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

 * }

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 &quot;as is&quot; 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 = &quot;WordCount&quot; Cancel CharLeft 1 n = CmpBookmarks(&quot;\Sel&quot;, &quot;WordCount&quot;) While n = 8 Or n = 6 If Asc(Selection$) > 47 Then count = count + 1 WordRight 1 n = CmpBookmarks(&quot;\Sel&quot;, &quot;WordCount&quot;) Wend EditGoTo .Destination = &quot;WordCount&quot; InsertBookmark .Name = &quot;WordCount&quot;, .Delete MsgBox &quot;Word Count: &quot; + Str$(count) End Sub In Word for Windows version 6.0:

Sub MAIN count = 0 EditBookmark .Name = &quot;WordCount&quot; Cancel CharLeft 1 n = CmpBookmarks(&quot;\Sel&quot;, &quot;WordCount&quot;) While n = 8 Or n = 6 If Asc(Selection$) > 47 Then count = count + 1 WordRight 1 n = CmpBookmarks(&quot;\Sel&quot;, &quot;WordCount&quot;) Wend EditGoTo .Destination = &quot;WordCount&quot; EditBookmark .Name = &quot;WordCount&quot;, .Delete MsgBox &quot;Word Count: &quot; + 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
 Verify that the Show Readability Statistics After Proofing option is selected:

 From the Tools menu, choose Options. Select the Grammar category in the options dialog box. 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. Select the paragraph(s) for which you want a word count. From the Tools menu, choose Grammar.</li> 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.)</li> Choose the No button when Word asks if you want to continue checking from the beginning of the document.</li></ol>

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