View Single Post
 
Old 03-24-2024, 08:26 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I think that looping through all fields is inefficient and would prefer a more direct Find method. This doesn't move the selection if there are no more Ref fields so you could add a complication for that wrinkle (and potentially allow the find to wrap).
Code:
Sub FindMeSeymour()
  ActiveWindow.View.ShowFieldCodes = True
  With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^d REF"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .MatchCase = False
    .Execute
  End With
  ActiveWindow.View.ShowFieldCodes = False
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote