Hi All

I have an ordinary document where if I look at File - Properties - Stats, my
wordcount is 256. This agrees with Tools -WordCount.
In VB I execute x = ActiveDocument.Words.Count and x is 331.
256 is the correct word count.
Can anyone explain how x becomes 331. It's not counting spaces because I
have 244 of them, and I'm showing hidden text.
Can VBA get the count from "File - Properties - stats" figure?

TIA

Ian B

Re: Variance in word count by Doug

Doug
Thu Nov 29 22:31:37 PST 2007

ActiveDocument.BuiltInDocumentProperties(wdPropertyWords) will return the
same number as shown under the Statistics tab of the File Properties dialog.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Ian B" <ian@(TakeOut)docspro.co.nz> wrote in message
news:%23nSoOrwMIHA.4948@TK2MSFTNGP02.phx.gbl...
> Hi All
>
> I have an ordinary document where if I look at File - Properties - Stats,
> my
> wordcount is 256. This agrees with Tools -WordCount.
> In VB I execute x = ActiveDocument.Words.Count and x is 331.
> 256 is the correct word count.
> Can anyone explain how x becomes 331. It's not counting spaces because I
> have 244 of them, and I'm showing hidden text.
> Can VBA get the count from "File - Properties - stats" figure?
>
> TIA
>
> Ian B
>
>
>
>



Re: Variance in word count by Julian

Julian
Fri Nov 30 01:54:51 PST 2007

Word count from VBA doesn't do the same as Word count from the Tools menu
(go figure!) - the former also counts e.g. paragraph marks (and some other
stuff I can't remember)... would that account for the discrepancy?

"Ian B" <ian@(TakeOut)docspro.co.nz> wrote in message
news:%23nSoOrwMIHA.4948@TK2MSFTNGP02.phx.gbl...
> Hi All
>
> I have an ordinary document where if I look at File - Properties - Stats,
> my
> wordcount is 256. This agrees with Tools -WordCount.
> In VB I execute x = ActiveDocument.Words.Count and x is 331.
> 256 is the correct word count.
> Can anyone explain how x becomes 331. It's not counting spaces because I
> have 244 of them, and I'm showing hidden text.
> Can VBA get the count from "File - Properties - stats" figure?
>
> TIA
>
> Ian B
>
>
>
>


Re: Variance in word count by Julian

Julian
Fri Nov 30 02:51:39 PST 2007

Forgot to say set a range object and do wdCount =
rangObj.ComputeStatistics(wdStatisticWords) - that gives the same results as
Tools... Word Count

e.g. wdCount = ActiveDocument.Range.ComputeStatistics(wdStatisticWords)

"Julian" <msforums@tiger2.demon.co.uk> wrote in message
news:uj5%23VczMIHA.6108@TK2MSFTNGP03.phx.gbl...
> Word count from VBA doesn't do the same as Word count from the Tools menu
> (go figure!) - the former also counts e.g. paragraph marks (and some other
> stuff I can't remember)... would that account for the discrepancy?
>
> "Ian B" <ian@(TakeOut)docspro.co.nz> wrote in message
> news:%23nSoOrwMIHA.4948@TK2MSFTNGP02.phx.gbl...
>> Hi All
>>
>> I have an ordinary document where if I look at File - Properties - Stats,
>> my
>> wordcount is 256. This agrees with Tools -WordCount.
>> In VB I execute x = ActiveDocument.Words.Count and x is 331.
>> 256 is the correct word count.
>> Can anyone explain how x becomes 331. It's not counting spaces because I
>> have 244 of them, and I'm showing hidden text.
>> Can VBA get the count from "File - Properties - stats" figure?
>>
>> TIA
>>
>> Ian B
>>
>>
>>
>>
>


Re: Variance in word count by fumei

fumei
Fri Nov 30 14:50:33 PST 2007

Yes indeed, the Words object does count paragraph marks, and other things.

Say a document with the following text (to keep it simple).

This is some text. <p>

So "This is some text." terminated by a paragraph mark.

File > Properties > Statistics Words = 4
Tools > Word Count = 4

Set a Range object:
Set r = ActiveDocument.Range

Using the SAME range object:

r.Words.Count = 6

r.ComputeStatistics(wdStatisticWords) = 4

The Words count returns 6 because the "words" are:

1. This
2. is
3. some
4. text
5. .
6. paragraph mark

The period is counted as a "word", as is the paragraph mark.

The reason? The tools such as File > Properties >Stats; Tools > Word Count;
and the VBA method ComputeStatistics all use internally defined delimiters.

"Words" does not.

There is a similar divergence regarding paragraphs themselves.

Make a brand new document. Insert a 3 x 3 table . Nothing more. Do NOT put
any text in the table. Make a Range object.

Set r = ActiveDocument.Range

You can also use Set r = ActiveDocument.Tables(1).Range. It does not matter.

r.ComputeStatistics(wdStatisticParagraphs) = 0
File > Properties > Statistics Paragraphs = 0
Tools > Word Count Paragraphs = 0

ActiveDocument.Paragraphs.Count = 13

13? The table is 3 x 3, which is 9 cells. Why 13?

Because:

Row1 = 3 cells PLUS End-Of-Row marker....4 paragraphs
Row2 = 3 cells PLUS End-Of-Row marker....4 paragraphs
Row3 = 3 cells PLUS End-Of-Row marker....4 paragraphs

Plus the (always) document terminating paragraph mark. Total = 13 paragraphs.


Now, put some text - This is some text - in Cell (1,1). Do NOT hit the Enter
key.

r.ComputeStatistics(wdStatisticParagraphs) = 1
File > Properties > Statistics Paragraphs = 1
Tools > Word Count Paragraphs = 1

ActiveDocument.Paragraphs.Count = 13

One should take great care when using any COUNT of words or paragraphs. In
particualr, if tables are involved, using a paragraph count has to be well
considered.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200711/1


Re: Variance in word count by fumei

fumei
Fri Nov 30 14:54:44 PST 2007

Just to make it worse......

This is some text.

Remember that Words.Count returned 6?

Change it to:

This is "some" text.

Words.Count = 8

1. This
2. is
3. "
4. some
5. "
6. text
7. .
8. paragraph mark

Each quotation mark is counted as a separate "word".

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200711/1


Re: Variance in word count by fumei

fumei
Fri Nov 30 14:56:35 PST 2007

Sorry, I was not perfectly clear.

This is "some" text.

If you make a Range of that:

r.ComputeStatistics(wdStatisticWords) = 4
r.Words.Count = 8

--
Message posted via http://www.officekb.com


Re: Variance in word count by Ian

Ian
Fri Nov 30 16:09:03 PST 2007

Thanks all

Ian B

"Ian B" <ian@(TakeOut)docspro.co.nz> wrote in message
news:%23nSoOrwMIHA.4948@TK2MSFTNGP02.phx.gbl...
> Hi All
>
> I have an ordinary document where if I look at File - Properties - Stats,
my
> wordcount is 256. This agrees with Tools -WordCount.
> In VB I execute x = ActiveDocument.Words.Count and x is 331.
> 256 is the correct word count.
> Can anyone explain how x becomes 331. It's not counting spaces because I
> have 244 of them, and I'm showing hidden text.
> Can VBA get the count from "File - Properties - stats" figure?
>
> TIA
>
> Ian B
>
>
>
>



Re: Variance in word count by Ian

Ian
Fri Nov 30 13:33:37 PST 2007

Thanks Doug & Julian - all sorted now.

Ian B

"Ian B" <ian@(TakeOut)docspro.co.nz> wrote in message
news:%23nSoOrwMIHA.4948@TK2MSFTNGP02.phx.gbl...
> Hi All
>
> I have an ordinary document where if I look at File - Properties - Stats,
my
> wordcount is 256. This agrees with Tools -WordCount.
> In VB I execute x = ActiveDocument.Words.Count and x is 331.
> 256 is the correct word count.
> Can anyone explain how x becomes 331. It's not counting spaces because I
> have 244 of them, and I'm showing hidden text.
> Can VBA get the count from "File - Properties - stats" figure?
>
> TIA
>
> Ian B
>
>
>
>