View Single Post
 
Old 10-21-2023, 03:33 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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

The macro IS replacing the quotes but there is a sneaky little option which tells Word that all quotes need to be converted to smart quotes and this is undoing the macro's work instantly. To actually get the results to stick around and keep the smart quotes function from running, you need to temporarily turn this setting off and turn it on again after the macro has run.
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])"
      .Replacement.Text = Chr(146) & "\1"
      .Font.Superscript = False       'to avoid footnote reference marks
      '.Replacement.Highlight = True
      .Wrap = wdFindContinue
      .MatchWildcards = True
      .Execute Replace:=wdReplaceAll
    End With
  Options.AutoFormatAsYouTypeReplaceQuotes = True
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 10-21-2023 at 04:42 AM. Reason: fixed typo spotted by vivka - thanks for that quality control
Reply With Quote