View Single Post
 
Old 08-26-2021, 07:41 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,164
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

Here is your code tidied up a bit. Note that the toggling of field codes makes an assumption that codes were not showing before the macro ran. That is risky so I changed those to explicitly set the value instead of toggling true/false.
Code:
Sub ReplaceCaptionStyle()
' Developed by Andrew Lockton (Guessed)
' Edited by laith93
' www.msofficeforums.com

' Showing all field codes (or by pressing Alt-F9):
  ActiveWindow.View.ShowFieldCodes = True
  
  With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    ' Replace "CapTbl" with your own alternative caption style for tables
    .Replacement.Style = ActiveDocument.Styles("CapTbl")
    .Text = "seq table"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchKashida = False
    .MatchDiacritics = False
    .MatchAlefHamza = False
    .MatchControl = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
    
    ' Replace "CapFig" with your own alternative caption style for figures
    .Replacement.ClearFormatting
    .Replacement.Style = ActiveDocument.Styles("CapFig")
    .Text = "seq figure"
    .Execute Replace:=wdReplaceAll
  End With
    
  ' Hiding all field codes (or by pressing Alt-F9):
  ActiveWindow.View.ShowFieldCodes = False
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote