Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Changing the Format of Existing Dates.
Written by Allen Wyatt (last updated August 24, 2024)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021
Aileen works with a lot of documents that have the date in a numeric format, such as 8/25/24. She needs to convert these dates to a different format, specifically August 25, 2024. She wonders if there is an easy way to make the change without needing to retype each date.
The answer depends, in large part, on the nature of the date you are changing. Dates in a Word document can either be straight text or a field. You can tell if the date is a field by simply moving the insertion point somewhere inside the date. If it is a field, then the entire date should be shaded in light gray once the insertion point is within the date.
If the date is a field, then you can right-click on the date and choose Edit Field from the resulting Context menu. You can then modify the field, including selecting a different date format in the Field Properties list.
If the date is regular text (not a field), then you need to look to a different solution. It is possible to go through the document and manually retype all the dates, but Aileen already found out that such an approach is tedious. This is where a macro can come in handy: to cure the tedium by programmatically doing what you would otherwise do by hand.
The following macro will step through a document, searching for all dates in the format m/d/yyyy. (There can be either one or two digits for either the month or day, but must be four digits for the year.) If a date matching this pattern is found, it is converted to the format mmmm d, yyyy.
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]{1,2})[/]([0-9]{1,2})[/]([0-9]{4})" .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 d, yyyy") Selection.Collapse wdCollapseEnd Else ' not a date - end loop FoundOne = False End If Loop End Sub
The key to this macro is the pattern stored in the .Text property. It searches for one or two digits (the month), followed by a slash, followed by one or two digits (the day), followed by a slash, followed by four digits (the year). If this pattern is matched, then it is checked to make sure it is a date. If it is, then the date is converted to a different format using the Format() function.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12197) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Word here: Changing the Format of Existing Dates.
Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!
If you want to decrease the size of spaces in some selected text, the best approach is to use a macro. This tip includes ...
Discover MoreIf you know how to create macros, you can easily create entire replacements for Word's internal commands. Here's all you ...
Discover MoreDo you need to copy, within a macro, a range of pages? Because pages can be so fluid in Word, this can be a bit tricky. ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments