VBA to change the legend field codes from the figure to the table


I would like to change all captions from one type to another. While not modifying any other filed codes accidentily.

The process I've come up with is two step: First changing the text inside the field code and the text before it.

i.e. from

Table { SEQ Table * ARABIC }


Figure { SEQ Figure * ARABIC }

I have experimented with manual editing and changing the type inside does not automaticaly change the label outside of the field.

To change the text I use Find/Replace, which works fine:

With Selection.Find
    .Style = ActiveDocument.Styles("Caption")
    .Text = "Figure"
    .Replacement.Text = "Table"
    .Forward = True
    .Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll

To do the field codes themslves I'm having issues. The following code will perform the change:

Dim rngTemp As Range
Set rngTemp = ActiveDocument.Fields(1).Code
rngTemp.Text = " SEQ Figure \* ARABIC "

however I can't make sure it only changes a specific type of field, i.e. captions. As it is the code changes any field based on its index number.

I'm also having trouble getting it to loop with a for/each replaceing the number with an i. I get an error saying "object does not suppor this method"

Any help would we wonderfull thank you.

Based on link above, how about the below code (Untested)

Dim oField As Field
Dim sCode As String
Dim bFoundOne As String

For Each oField In ActiveDocument.Fields

    If oField.Type = wdFieldSequence Then

        sCode = oField.Code

        If InStr(sCode, "Table") <> 0 Then oField.Code = Replace(sCode, "Table", "Figure")

    End If