B
Benjamino5
Below is the code. I'm trying to find every instance of the character style
"Index" in the document and insert an XE (Index) field in each case.
What's happening is that the "While .Found" loop finds the first item, then
finds it again, and again, etc., and I end up with many identical XE fields
added to that first item.
I think the problem must be redefining "r" somehow by using it in the
MarkEntries line, but I'm not sure, and I'm not sure how to fix it.
Thanks!
Ben
__________________________________
Sub MarkEntries(adoc As Document)
' finds every instance of the character style
' "Index" and marks it with an XE field
Dim f As Find
Dim r As Range
Set r = adoc.Range
Set f = r.Find
With f
.Format = True
.Style = "Index"
.Forward = True
.Wrap = wdFindStop
.Execute
End With
While f.Found
adoc.Indexes.MarkEntry Range:=r, Entry:=r.Text
f.Execute
Wend
End Sub
"Index" in the document and insert an XE (Index) field in each case.
What's happening is that the "While .Found" loop finds the first item, then
finds it again, and again, etc., and I end up with many identical XE fields
added to that first item.
I think the problem must be redefining "r" somehow by using it in the
MarkEntries line, but I'm not sure, and I'm not sure how to fix it.
Thanks!
Ben
__________________________________
Sub MarkEntries(adoc As Document)
' finds every instance of the character style
' "Index" and marks it with an XE field
Dim f As Find
Dim r As Range
Set r = adoc.Range
Set f = r.Find
With f
.Format = True
.Style = "Index"
.Forward = True
.Wrap = wdFindStop
.Execute
End With
While f.Found
adoc.Indexes.MarkEntry Range:=r, Entry:=r.Text
f.Execute
Wend
End Sub