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

That changes things a bit. I've modified the earlier searches and added a new section at the end
Code:
Sub DPU_TimeFormat2()
  Dim Rng As Range
  Application.ScreenUpdating = False
  Set Rng = ActiveDocument.Range
  With Rng.Find
    .MatchWildcards = True
  
    'Delete periods in a.m./p.m.
    .Text = "([APap]).([mM])."
    .Replacement.Text = "\1\2"
    .Execute Replace:=wdReplaceAll
    .Text = "([APap]).([mM])"
    .Replacement.Text = "\1\2"
    .Execute Replace:=wdReplaceAll
    
    .Text = "([0-9]) ([APap])([mM])>"     'without space between number and a/p
    .Replacement.Text = "\1\2\3"
    .Execute Replace:=wdReplaceAll
    
    .Text = "([0-9])AM>"                  'AM to am
    .Replacement.Text = "\1am"
    .Execute Replace:=wdReplaceAll
    .Text = "([0-9])PM>"                  'PM to pm
    .Replacement.Text = "\1pm"
    .Execute Replace:=wdReplaceAll

    'Change period for colon in times
    .Text = "([0-9]{1,2}).([0-9]{2})([ap])m"
    .Replacement.Text = "\1:\2\3m"
    .Execute Replace:=wdReplaceAll
    
    'Expand abbreviated hours
    .Text = " ([0-9]{1,2})([ap])m"
    .Replacement.Text = " \1:00\2m"
    .Execute Replace:=wdReplaceAll
    
  End With
  Application.ScreenUpdating = True
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 10-20-2021 at 01:46 PM.
Reply With Quote