Skip to content

Instantly share code, notes, and snippets.

@ishu3101
Created March 13, 2017 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishu3101/66a71870202aa9420696a9b393750f0a to your computer and use it in GitHub Desktop.
Save ishu3101/66a71870202aa9420696a9b393750f0a to your computer and use it in GitHub Desktop.
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