A family of Microsoft word processing software products for creating web, email, and print documents.
Change the search and replace lines as follows:
.Text = "the ([0-9]{1,2})[dhnrst]{2} of (" & myMonth(i) & ")"
.Replacement.Text = "\1 \2"
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I'm trying to create a macro to change dates from the format "the 12th of June" to "12 June", etc.
I found this piece of code that seems like a good starting point but I haven't been able to work out how to successfully modify it.
Thanks for any help!
Sub ChangeDateFormatWithReplaceCommand()
Dim myMonth(1 To 12) As String
myMonth(1) = "January"
myMonth(2) = "February"
myMonth(3) = "March"
myMonth(4) = "April"
myMonth(5) = "May"
myMonth(6) = "June"
myMonth(7) = "July"
myMonth(8) = "August"
myMonth(9) = "September"
myMonth(10) = "October"
myMonth(11) = "November"
myMonth(12) = "December"
For i = 1 To 12
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(" & myMonth(i) & ")" & " ([0-9]{1,2}),"
.Replacement.Text = "\2 \1"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next i
End Sub
A family of Microsoft word processing software products for creating web, email, and print documents.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Answer accepted by question author
Change the search and replace lines as follows:
.Text = "the ([0-9]{1,2})[dhnrst]{2} of (" & myMonth(i) & ")"
.Replacement.Text = "\1 \2"