I'm using Word 2003. I have a for next loop to search through indexes { XE "
"} in my document. I'm using a find statement to find the " XE ", store the
string in a variable, compare it to the next found string, and delete if it
is a duplicate. The number of indexes in the document will vary. How can I
have the code loop until the end of the document is reached. I don't know
the syntax to use, if I can create a range based on words or indexes, or
count the number of indexes first and then use a for next loop.

Signature
GlennMc
Greg - 24 Mar 2006 20:20 GMT
GlennMc.
You should be able to use .Wrap = wdFindStop.
Here is an example:
Sub Test()
Dim orng As Range
Set orng = ActiveDocument.Range
With orng.Find
.Text = "some text"
.Wrap = wdFindStop
Do While .Execute
If .Found Then
orng.Font.Color = wdColorBlue
End If
Loop
End With
End Sub
Dave Lett - 24 Mar 2006 22:15 GMT
Hi Glenn,
You might find your task easier if you use the fields collection, as in the
following example:
Dim iFld As Integer
Dim sCurField As String
Dim sPrevField As String
sPrevField = ""
For iFld = ActiveDocument.Fields.Count To 1 Step -1
If ActiveDocument.Fields(iFld).Type = wdFieldIndexEntry Then
sCurField = ActiveDocument.Fields(iFld).Code
If sCurField = sPrevField Then
ActiveDocument.Fields(iFld).Delete
End If
sPrevField = ActiveDocument.Fields(iFld).Code
End If
Next iFld
HTH,
Dave
> I'm using Word 2003. I have a for next loop to search through indexes {
> XE "
[quoted text clipped - 7 lines]
> the syntax to use, if I can create a range based on words or indexes, or
> count the number of indexes first and then use a for next loop.
GlennMc - 26 Mar 2006 23:58 GMT
Very slick Dave. Thanks.

Signature
GlennMc
> Hi Glenn,
>
[quoted text clipped - 28 lines]
> > the syntax to use, if I can create a range based on words or indexes, or
> > count the number of indexes first and then use a for next loop.