If I find a word in the document (such as through myWord.Find.Execute), how
can tell which word number this is within the whole document?

Re: Word Number Index by Helmut

Helmut
Wed Dec 14 11:02:23 CST 2005

Hi George,

what is myWord?
The selection range?

Then like this, according to Word's definition of a word:

Sub test000123()
Dim rSlc As Range
Set rSlc = Selection.Range
With rSlc.Find
.Text = "quick"
If .Execute Then
rSlc.Start = ActiveDocument.Range.Start
MsgBox rSlc.Words.Count
End If
End With
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"



Re: Word Number Index by Jonathan

Jonathan
Wed Dec 14 11:33:48 CST 2005


"George Lee" <GeorgeLee@discussions.microsoft.com> wrote in message
news:5FAD3C70-5486-4AC8-8FF8-8460058032D7@microsoft.com...
> If I find a word in the document (such as through myWord.Find.Execute),
> how
> can tell which word number this is within the whole document?

Take a look at this article

Determine the index number of the current paragraph, table, section ...
http://www.word.mvps.org/FAQs/MacrosVBA/GetIndexNoOfPara.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org


Re: Word Number Index by GeorgeLee

GeorgeLee
Wed Dec 14 12:33:56 CST 2005

Sorry if that was unclear, myWord is a Range.

I understand your code (rSlc.Words.Count) shows the number of words in the
selection range and you could even specify the exact word (rSlc.Words(x)).
However, I was asking to find out what that word is in the overall document.
Some structures have an index concept (that that item is the x-th item in the
document) and I was wanting to get that information for a word.

For other reasons I need to use a seperate range.

"Helmut Weber" wrote:

> Hi George,
>
> what is myWord?
> The selection range?
>
> Then like this, according to Word's definition of a word:
>
> Sub test000123()
> Dim rSlc As Range
> Set rSlc = Selection.Range
> With rSlc.Find
> .Text = "quick"
> If .Execute Then
> rSlc.Start = ActiveDocument.Range.Start
> MsgBox rSlc.Words.Count
> End If
> End With
> End Sub
>
> --
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
>
>
>

Re: Word Number Index by Helmut

Helmut
Wed Dec 14 22:25:50 CST 2005

Hi George,

have you tried it?

>I understand your code (rSlc.Words.Count) shows the number
>of words in the selection range

The word you were searching for,
is the nth word in the documents main story.
As before counting the words, I reset the range's
start to be the start of the document's range.

rSlc.Start = ActiveDocument.Range.Start

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"




Re: Word Number Index by GeorgeLee

GeorgeLee
Thu Dec 15 11:12:02 CST 2005

Thanks to you and Helmut.

It's one of those things that isn't intuitive but after thinking about it,
it does seem obvious, doesn't it?

"Jonathan West" wrote:

>
> "George Lee" <GeorgeLee@discussions.microsoft.com> wrote in message
> news:5FAD3C70-5486-4AC8-8FF8-8460058032D7@microsoft.com...
> > If I find a word in the document (such as through myWord.Find.Execute),
> > how
> > can tell which word number this is within the whole document?
>
> Take a look at this article
>
> Determine the index number of the current paragraph, table, section ...
> http://www.word.mvps.org/FAQs/MacrosVBA/GetIndexNoOfPara.htm
>
>
> --
> Regards
> Jonathan West - Word MVP
> www.intelligentdocuments.co.uk
> Please reply to the newsgroup
> Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
>
>