Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jun 2003
    Location
    Sydney, New South Wales, Australia
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word counts disagree (Word 2000 / 2002)

    I often use a little macro for displaying the number of words in selected text. It uses Selection.Words.Count. I have just used it to count the words in the whole document (after Select All) and found that it differs from the count offered under File | Properties | Statistics. The counts are 810 and 688 respectively. My document has no headers or footers and no section breaks, so everything is inside the one Story. How can these counts be so wildly different? I haven't actually sat down and counted them by hand to find out which one is right but a count of a smaller sample indicates that the macro's count is wrong. Any ideas?
    Macro text is as follows: MsgBox "The selection contains " & Str(Selection.Words.Count) & " words."

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Word counts disagree (Word 2000 / 2002)

    According to Microsoft, the Words collection in VBA includes puncuation and paragraph marks as separate words! See WD2000: Word Count for Comments Incorrect Using Words Property for a description.

    The workaround is to use Selection.Range.ComputeStatistics(wdStatisticWords )

  3. #3
    New Lounger
    Join Date
    Jun 2003
    Location
    Sydney, New South Wales, Australia
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word counts disagree (Word 2000 / 2002)

    Thanks Hans. The new method works perfectly.

    You're a gem!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •