Convert date text to mm/dd/yyyy

K

Kim

I started this macro, but I don't know how to make it loop within the
selection. (I use this macro to highlight a paragraph or table, and
search for all spelled out dates and convert the find to mm/dd/yyyy
number format). I want the macro to continue within my selection. Is
this possible?


Selection.Find.ClearFormatting
With Selection.Find
.text = "(<[ADFJMNOS]*>) ([0-9]{1,2}), ([0-9]{4})"
.MatchWildcards = True
End With
Selection.Find.Execute

If IsDate(Selection.Range) Then
Selection.Range = Format(Selection.Range, "mm/dd/YYYY")
End If


End Sub

Thanks,
Kim
 
G

Graham Mayor

Sub ReformatDate()
Dim rDate As Range
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:="(<[ADFJMNOS]*>) ([0-9]{1,2}),
([0-9]{4})", _
MatchWildcards:=True, _
Wrap:=wdFindStop, Forward:=True) = True
Set rDate = Selection.Range
If IsDate(rDate) Then
rDate = format(rDate, "MM/dd/yyyy")
End If
Loop
End With
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top