Hi I am trying to replace some placeholder text eg. "Ins1Fig" Under my figures in word with dynamic caption field codes by replacing with field code brackets and the codes "SEQ Figure \* ARABIC" .
It kind of works but gets confused and adds too many field code brackets at the end of the for loop. Is there a more robust way of doing this?
Thanks,
Sub MakeFieldCodes()
'
For i = 1 To 50
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Ins" & i & "Fig"
.Replacement.Text = "SEQ Figure \* ARABIC"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
If Selection.Find.Execute Then
' If Selection.Find.Text = "Ins" & i & "Fig" Then
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
With Selection.Find
.Text = "Ins" & i & "Fig"
.Replacement.Text = "SEQ Figure \* ARABIC"
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
' Selection.Find.Text = ""
End If
Next
End Sub