Created
March 13, 2017 02:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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