View Single Post
 
Old 11-30-2023, 09:52 AM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 208
RobiNew is on a distinguished road
Question Code works only in isolation not within a larger set

I have two code versions to obtain the same result. They both work perfectly in isolation. When inserted in a larger set of commands they do not work at all on the same document. No error occurs. Can someone help? Thanks!
Code:
Sub Replace1()
Dim aRng As Range
Set aRng = ActiveDocument.StoryRanges(1)
    With aRng.Find
        .Text = "(^0146)" & "(^0171)" '« (146=’)
        .Replacement.Text = "\1" & "^0187" '»
        .MatchWildcards = True
        .Execute Replace:=wdReplaceAll
    End With
End Sub
Code:
Sub Replace2()
Dim aRng As Range
Set aRng = ActiveDocument.StoryRanges(1)
    With aRng.Find
      .MatchWildcards = False
      .Text = Chr(146) & Chr(171) '« (146=’)
      .Replacement.Text = Chr(146) & Chr(187) '»
      .Execute Replace:=wdReplaceAll
    End With
End Sub
Reply With Quote