When is a word not a word? Different counts by vba and status bar

User avatar
Charles Kenyon
3StarLounger
Posts: 320
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

When is a word not a word? Different counts by vba and status bar

Post by Charles Kenyon »

:scratch: When I use vba to count the number of words in a document, I get a result different from what I see in the status bar or would count manually.
00 deleteme 10.png
What is being counted as a word in vba that is not what I might consider to be a word?
You do not have the required permissions to view the files attached to this post.
Last edited by Charles Kenyon on 12 Sep 2020, 00:47, edited 1 time in total.
Attorney Charles Kenyon

Templates in Microsoft Word http://www.addbalance.com/usersguide/templates.htm
Modifying the QAT http://addbalance.com/word/QATmodification.htm

User avatar
HansV
Administrator
Posts: 69054
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: When is a word not a word? Different counts by vba and status bar

Post by HansV »

ActiveDocument.Words.Count includes a lot of stuff that we normally don't consider to be words. Why? Microsoft's ways are inscrutable.

ActiveDocument.ComputeStatistics(wdStatisticWords) returns the value you would expect.
Regards,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 11305
Joined: 24 Jan 2010, 23:23
Location: paused.undefined.exposed

Re: When is a word not a word? Different counts by vba and status bar

Post by ChrisGreaves »

Charles Kenyon wrote:
05 Sep 2020, 20:15
When I use vba to count the number of words in a document, I get a result different from what I see in the status bar or would count manually.
I know that over the years I have found three, possibly four different count results reurned for the one chunk of text.
There is File, Properties, Statistics,
then there is a field {INFO NumWords}
then there is a VBA proprty e.g. "activedocument.Words.Count"
What is being counted as a word in vba that is not what I might consider to be a word?
I don't know the answer to this. One way to find out would be to pare down an example of text with differing counts until the counts agree, and then recall the most recently-pared item of punctuation.

Me? I am still smarting over the forum's search engine treating the hyphen as a space in "uh-oh" (grin)

Cheers
chris
People who live in glass houses shouldn’t grow zucchinis

User avatar
Jay Freedman
Microsoft MVP
Posts: 1099
Joined: 24 May 2013, 15:33
Location: Willow Grove, PA

Re: When is a word not a word? Different counts by vba and status bar

Post by Jay Freedman »

The ActiveDocument.Words collection includes punctuation marks (periods, commas, question and exclamation marks, quotes, and others, but not apostrophes) and paragraph marks as separate "words". For some reason a manual line break (Shift+Enter) is counted as two words. The other methods of getting word counts ignore these things.

User avatar
Charles Kenyon
3StarLounger
Posts: 320
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: When is a word not a word? Different counts by vba and status bar

Post by Charles Kenyon »

Thank you Hans and Chris.
Attorney Charles Kenyon

Templates in Microsoft Word http://www.addbalance.com/usersguide/templates.htm
Modifying the QAT http://addbalance.com/word/QATmodification.htm

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 11305
Joined: 24 Jan 2010, 23:23
Location: paused.undefined.exposed

Re: When is a word not a word? Different counts by vba and status bar

Post by ChrisGreaves »

Charles Kenyon wrote:
06 Sep 2020, 03:38
Thank you Hans and Chris.
And Jay "a manual line break (Shift+Enter) is counted as two words" Freedman.

Don't forget to assign some blame to Jay for adding spice to the witches brew (Huge grin!)

Cheers
Chris
People who live in glass houses shouldn’t grow zucchinis

User avatar
Jay Freedman
Microsoft MVP
Posts: 1099
Joined: 24 May 2013, 15:33
Location: Willow Grove, PA

Re: When is a word not a word? Different counts by vba and status bar

Post by Jay Freedman »

ChrisGreaves wrote:
06 Sep 2020, 09:39
Don't forget to assign some blame to Jay for adding spice to the witches brew (Huge grin!)
Well, Halloween is less than 60 days away. The local market has already stocked up on candy and spiced wafers, so I'm just getting into the spirit (or is that spirits?).

User avatar
Charles Kenyon
3StarLounger
Posts: 320
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: When is a word not a word? Different counts by vba and status bar

Post by Charles Kenyon »

Thank you, Jay, as well.
I quoted you in response to a related question in another file. Apparently the Windows explorer count of words is related to the vba definition.

This should be scary enough for anyone.
perplex.jpg
You do not have the required permissions to view the files attached to this post.
Attorney Charles Kenyon

Templates in Microsoft Word http://www.addbalance.com/usersguide/templates.htm
Modifying the QAT http://addbalance.com/word/QATmodification.htm

User avatar
Jay Freedman
Microsoft MVP
Posts: 1099
Joined: 24 May 2013, 15:33
Location: Willow Grove, PA

Re: When is a word not a word? Different counts by vba and status bar

Post by Jay Freedman »

Interestingly, Bob wrote that 20 years ago. Plus ça change, plus ça même chose.

User avatar
Charles Kenyon
3StarLounger
Posts: 320
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: When is a word not a word? Different counts by vba and status bar

Post by Charles Kenyon »

I now have a different meme...

:cheers:
perplex2.png
You do not have the required permissions to view the files attached to this post.
Attorney Charles Kenyon

Templates in Microsoft Word http://www.addbalance.com/usersguide/templates.htm
Modifying the QAT http://addbalance.com/word/QATmodification.htm