I'm getting into an awful muddle in trying to find a series of SEQ fields formatted with a particular style.
Dim strSearch As String
Dim strReplace As String
Dim strSEQtype As String
Dim objRange As Range, objRangeNext As Range, objRange3 As Range
ActiveWindow.View.ShowFieldCodes = True
strSEQtype = "Table"
' restart sequence after each instance of custom style
Set objRange = ActiveDocument.Range
With objRange.Find
.Format = True
.Style = ActiveDocument.Styles("Caption Tables")
While .Execute
Set objRangeNext = objRange.Duplicate
objRangeNext.Collapse wdCollapseEnd
objRangeNext.End = ActiveDocument.Range.End
With objRangeNext.Find
.Format = True
.Style = ActiveDocument.Styles("Caption Tables")
If .Execute Then
objRange.End = objRangeNext.Start - 1
Else
objRange.End = ActiveDocument.Range.End
End If
' At this point, objRange covers the range between two
' instances of strCustStyle, or the range following
' the last instance. Now look for the first SEQ field
' within that range.
Set objRange3 = objRange.Duplicate
With objRange3.Find
.Text = "Seq " & strSEQtype & " \* ARABIC"
If .Execute Then
If objRange3.InRange(objRange) Then
objRange3.Text = "Seq " & strSEQtype & " \* ARABIC \r 1"
End If
End If
End With
End With
objRange.Collapse wdCollapseEnd
Wend
End With
As you can see, the field I want to find has the string "SEQ Table \* ARABIC" and I want to replace it with "SEQ Table \* ARABIC \r 1"
When I run the procedure it goes into circular mode and I have to force it to stop.
Could anyone suggest please, how I could simplify the code so that it does replace the field?
Thanks for any help.
Roderick