Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-16-2018, 08:12 AM
mathosborne mathosborne is offline Find and Replace with Field Codes Windows 7 64bit Find and Replace with Field Codes Office 2013
Novice
Find and Replace with Field Codes
 
Join Date: Jul 2018
Posts: 1
mathosborne is on a distinguished road
Default Find and Replace with Field Codes

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
Reply With Quote
 

Tags
field codes, find and replace

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace with Field Codes Find and replace a text with a field eduzs Word VBA 6 02-23-2018 05:19 PM
Find and Replace with Field Codes Find & Replace text in Field Code across multiple documents RPM7 Word VBA 6 05-12-2017 12:58 AM
Find and Replace with Field Codes 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:20 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft