View Single Post
 
Old 10-21-2023, 10:34 AM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 302
vivka is on a distinguished road
Default

Explanation: your code looks for chr(145) followed by any digit & any char but ^02 and then replaces these THREE chars with TWO chars, which are chr(146) & the digit, thus loosiing the third char.

Code:
 Sub SingleBeforeDigit()
'Replace Chr(145) with Chr(146) before a digit (as in ’95)

Dim oRng As range
  Set oRng = ActiveDocument.range
  Options.AutoFormatAsYouTypeReplaceQuotes = False
    With oRng.Find
        .ClearFormatting
        .text = Chr(145) & "([0-9][!^02])" 'to avoid footnote ref. marks
        .Replacement.text = Chr(146) & "\1"
        .Forward = True
        .Wrap = wdFindStop
        .MatchWildcards = True
        .Execute Replace:=wdReplaceAll
    End With
  Options.AutoFormatAsYouTypeReplaceQuotes = True
End Sub
Reply With Quote