![]() |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
I wouldn't necessarily use a macro for this but you could record the following actions.
Make the field you need and cut it to your clipboard. Then use a wildcard find and replace Find: Ins[0-9]{1,2}Fig Replace: ^c Select All Update Fields
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
| Tags |
| field codes, find and replace |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Find and replace a text with a field
|
eduzs | Word VBA | 6 | 02-23-2018 05:19 PM |
Find & Replace text in Field Code across multiple documents
|
RPM7 | Word VBA | 6 | 05-12-2017 12:58 AM |
Macro to find text and replace with form field containing that text
|
iiiiifffff | Word VBA | 16 | 06-04-2016 01:47 AM |
| Macro to find coloured text and replace with form-field/formtext containing that text | tarktran | Word VBA | 1 | 11-26-2014 08:12 AM |
| Formula Field using Field Codes | hunter2193 | Word | 3 | 04-05-2013 04:58 AM |