Re: ComputeStatistics not working on a selection by Larry
Larry
Thu Aug 14 12:39:32 CDT 2003
It's just bland, filler text, and it doesn't matter what the text is.
Here, I just tested the code again on the most meaningless,
formatting-free text with Arial font. I selected some of it.
ToolsWordCount (which is always correct) told me there were 40 words in
the selection. Then I ran the code I showed you, and it returned a
result of 23 words.
This is a test. This is a test. This is a test. This is a test. This
is a test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This is a test. This is a
test. This is a test. This is a test. This is a test.
Also, I tested the same thing on another computer that also has Word 97,
and the code doesn't work there either. Also, it is often correct on
the first run of the macro. Then, if you keep increasing the size of
the selection that you're testing, at a certain point you'll start
getting incorrect results.
Also, Doug, I have not sent duplicate messages to newsgroups. The
current message is correctly multiposted to three groups.
Larry
"Doug Robbins - Word MVP" <dkr@mvps.org> wrote in message
news:eFtrv#jYDHA.3232@tk2msftngp13.phx.gbl...
> Hi Larry,
>
> It returns the correct result for me. Paste the text from the range
that
> gives the error into a message so that we can see if there is anything
in it
> that might cause a problem.
>
> AND
>
> Please do not spam the newsgroups by posting the same question
separately to
> multiple newsgroups. Rather, if you are not sure which is the most
> appropriate newsgroup, insert the names of those which you think might
be
> appropriate into the header of a single message. When you do that, an
> answer in one newsgroup will automatically appear in all of the
newsgroups
> to which you posted. That will make it easier for you to find
responses and
> can also reduce the possibility of someone developing an answer to a
> question that has already been answered.
>
> Please post any further questions or followup to the newsgroups for
the
> benefit of others who may be interested. Unsolicited questions
forwarded
> directly to me will only be answered on a paid consulting basis.
>
> Hope this helps
> Doug Robbins - Word MVP
> "Larry" <larry328@att.net> wrote in message
> news:umQ1c4iYDHA.652@tk2msftngp13.phx.gbl...
> >
> >
> > I'm wondering if I can get any further help on this. Martinique
tried
> > bravely to help but we ran into a wall. According to VBA help in
Word
> > 97, this code should count the number of words in the range, which
in
> > this case is the selection. My test code below follows the sample
> > presented in help. Yet, as I discussed with martinique, the
resuling
> > number is only occasionally correct. Most of the time it's much
lower
> > (sometimes higher) than the correct number. I tried it on another
> > computer, and it wouldn't work there either. Meanwhile, Martinique
> > tried it over and over, and it was always correct.
> >
> > Since I'm following the Help sample so closely, I can't see what I'm
> > doing wrong. Does anyone have any ideas of why this is not working?
> >
> > Dim r As Range
> > Set r = Selection.Range
> > WordCount = r.ComputeStatistics(Statistic:=wdStatisticWords)
> >
> > MsgBox "Words in selection: " & WordCount, vbOKOnly, "Word
> > Counter"
> >
> >
> >
> >
> >
> >
> >
>
>