Word for Windows: How to Get a Word Count for a Text SelectionLast reviewed: July 30, 1997Article ID: Q83149 |
The information in this article applies to:
SUMMARYMicrosoft 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 INFORMATIONWARNING: 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 1You 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 SubIn Word for Windows version 6.0:
Sub MAINcount = 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 SubNote: This macro does not work correctly if the selection contains the document's last paragraph marker.
Workaround 2In 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
REFERENCES"Microsoft Word for Windows User's Guide," version 2.0, page 285-287
|
KBCategory: kbmacro kbhowto
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |