View Full Version : How to write a macro to count words in MS Word 2000
tiltypig
05-04-2005, 06:21 PM
I want to make a macro that will count certain words in a document (e.g. all the words in the third column in a table.) I want it to use the same criteria when counting words that it would if you selected Tools...->Word Count... from the menu.
Why is this so damn hard?
The Selection.Words.Count property apparently counts punctuation and paragraph marks as separate words, so I was a few hundred words off in my test file.
Can anyone help me out with this?
MsWhatsit
05-04-2005, 06:47 PM
If you select text and then use Tools --> Word Count, it will count only the words in the selection. Only helpful if the words you want to count are contiguous, I realize, but thought I'd mention it in case it helps.
Reply
05-05-2005, 12:34 AM
See the "Remarks" section of this page. (http://msdn.microsoft.com/library/en-us/vbawd11/html/woobjWords1_HV05214285.asp).
The Count property for this collection in a document returns the number of items in the main story only. To count items in other stories use the collection with the Range object. Also, the Count property includes punctuation and paragraph marks in the total. If you need a count of the the actual words in a document, use the Word Count dialog box. The following example retrieves the number of words in the active document and assigns the value to the variable numWords.
Set temp = Dialogs(wdDialogToolsWordCount)
' Execute the dialog box in order to refresh its data.
temp.Execute
numWords = temp.Words
vBulletin® v3.7.3, Copyright ©2000-2013, Jelsoft Enterprises Ltd.