cross references collection & instr problem

W

Where am I?

Hello,
Word 2002.
I am attempting to loop through the cross references collection, find a
match based on some text that I have already captured and insert a cross
reference to the item. The code is given below. The instr command does not
resolve correctly but using the debug window there should be a value found.
Please help.

Sub Generic_References(toref$)
Dim i%, x%
myHeadings = ActiveDocument.GetCrossReferenceItems(wdRefTypeHeading)
x% = 1
For i% = 1 To UBound(myHeadings)
If InStr(myHeadings(i%), toref$) <> 0 Then
Selection.InsertCrossReference ReferenceType:=wdRefTypeHeading, _
ReferenceKind:=wdNumberRelativeContext, ReferenceItem:=i%
Selection.TypeText " "
Exit For 'once it is found it exits
End If
Next i
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top