Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 10-21-2023, 03:33 AM
Guessed's Avatar
Guessed Guessed is offline Replace apostrophe mark before a digit Windows 10 Replace apostrophe mark before a digit 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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace apostrophe mark before a digit Find/replace - remove a space in 4 digit numbers lalywizz Word 5 10-08-2021 09:27 AM
Replace apostrophe mark before a digit Trying to change the last digit in a column of 10 digit entries arkansawyer16 Excel 10 04-06-2020 02:03 PM
Regex/wildcard search for dates with 2-digit and 4-digit years Marrick13 Word VBA 2 01-29-2016 07:04 AM
Replace apostrophe mark before a digit A challenging digit by digit manipulation, rotate the digit in range of 0 to 9 laucn Excel Programming 14 05-17-2015 12:12 PM
Replace apostrophe mark before a digit Apostrophe-like mark appearing next to page numbers Natalie Word 2 04-26-2012 05:17 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft