The Straight Dope

Go Back   Straight Dope Message Board > Main > General Questions

Reply
 
Thread Tools Display Modes
  #1  
Old 05-04-2005, 06:21 PM
tiltypig tiltypig is offline
Guest
 
Join Date: Apr 2005
How to write a macro to count words in MS Word 2000

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?
Reply With Quote
Advertisements  
  #2  
Old 05-04-2005, 06:47 PM
MsWhatsit MsWhatsit is offline
Guest
Member
 
Join Date: Jul 2000
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 With Quote
  #3  
Old 05-05-2005, 12:34 AM
Reply Reply is offline
Guest
 
Join Date: Jul 2003
See the "Remarks" section of this page..

Quote:
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.

Code:
Set temp = Dialogs(wdDialogToolsWordCount)
' Execute the dialog box in order to refresh its data.
temp.Execute
numWords = temp.Words
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:56 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Send questions for Cecil Adams to: cecil@chicagoreader.com

Send comments about this website to: webmaster@straightdope.com

Terms of Use / Privacy Policy

Advertise on the Straight Dope!
(Your direct line to thousands of the smartest, hippest people on the planet, plus a few total dipsticks.)

Publishers - interested in subscribing to the Straight Dope?
Write to: sdsubscriptions@chicagoreader.com.

Copyright © 2013 Sun-Times Media, LLC.