P
Poseur
One of the documents I have to prepare regularly requires
dates spelled out ("March 16, 2006") which takes longer than
3/16/06. So, here's my macro. I post this for 2 reasons:
1. It might be of use to someone else.
2. I love seeing how the really great coders take something
like this and make it more elegant, contract it into a couple
lines of code, and point out the pitfalls.
Public Sub Convert_Dates_From_Short_To_Longer()
Dim rng As Range
Dim res As Boolean
Set rng = ActiveDocument.Range(Start:=0, End:=0)
Do
With rng.Find
.Forward = True
.MatchWholeWord = False
.MatchWildcards = True
.Wrap = wdWrapContinue = True
res = .Execute(FindText:="[0-9]{1,2}/[0-9]{1,2}/
[0-9]{2,4}")
If IsDate(rng.Text) Then
rng.Text = Format(CDate(DateValue
(rng.Text)), "mmm dd, yyyy")
End If
rng.Collapse Direction:=wdCollapseEnd
End With
Loop While res
End Sub
dates spelled out ("March 16, 2006") which takes longer than
3/16/06. So, here's my macro. I post this for 2 reasons:
1. It might be of use to someone else.
2. I love seeing how the really great coders take something
like this and make it more elegant, contract it into a couple
lines of code, and point out the pitfalls.
Public Sub Convert_Dates_From_Short_To_Longer()
Dim rng As Range
Dim res As Boolean
Set rng = ActiveDocument.Range(Start:=0, End:=0)
Do
With rng.Find
.Forward = True
.MatchWholeWord = False
.MatchWildcards = True
.Wrap = wdWrapContinue = True
res = .Execute(FindText:="[0-9]{1,2}/[0-9]{1,2}/
[0-9]{2,4}")
If IsDate(rng.Text) Then
rng.Text = Format(CDate(DateValue
(rng.Text)), "mmm dd, yyyy")
End If
rng.Collapse Direction:=wdCollapseEnd
End With
Loop While res
End Sub