Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Microsoft Word Macro to change all instances of date from 2017-03-15 to March 2017 Format
Sub GetDateAndReplace()
Dim FoundOne As Boolean
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
FoundOne = True ' loop at least once
Do While FoundOne ' loop until no date is found
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([0-9]{4})[-]([0-9]{1,2})[-]([0-9]{1,2})"
.Format = True
.Forward = True
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceNone
' check the find to be sure it's a date
If IsDate(Selection.Text) Then
Selection.Text = Format(Selection.Text, "mmmm yyyy")
Selection.Collapse wdCollapseEnd
Else ' not a date - end loop
FoundOne = False
End If
Loop
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.