Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. 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: Generating a List of Dates.

Generating a List of Dates

Written by Allen Wyatt (last updated March 13, 2021)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


1

For some documents, it is helpful to have a list of dates that you can use as the basis for your work. For instance, you may have to create a report that lists all the dates between now and the end of the year, along with a person's name or a project name to the right of the date. The starting point, of course, is getting the list of dates.

There are a couple of ways you can approach generating the list. One easy method is to use Excel in conjunction with Word. Excel's AutoFill feature makes generating a list of dates amazingly easy. Once you have the list in Excel, you can then copy and paste it into the Word document, or you can use mail merge to merge the dates into the document (if that approach is appropriate for your needs).

If you prefer to not use Excel for some reason, the best solution is to use a macro. The following macro very quickly creates a list of all the dates for the year 2021:

Sub PrintYearDays()
    Dim StartDate As Date
    Dim T As Integer

    StartDate = #12/31/2020#

    For T = 1 To 365
        Selection.TypeText Text:=Format(StartDate + T, _
          "mmmm dd yyyy")
        Selection.TypeParagraph
    Next T
End Sub

Notice that the macro works by setting the StartDate variable equal to the last day of 2020, and then the For ... Next loop steps through 365 days. If you want to have the macro work for some other date range, just change the starting date, along with the ending value of the For ... Next loop.

If you need to create date lists, and you never quite know what the beginning and ending dates in the range will be, then a different macro approach makes more sense. The following macro asks you for both a beginning and ending date:

Sub ListDates()
    Dim ListDate as Date
    Dim StartDate As Date
    Dim EndDate As Date
    Dim Repeats As Integer

    'Gets user input
    StartDate = InputBox("Please enter the starting date.", _
      "Start Date", "Start Date")
    EndDate = InputBox("Please enter the ending date.", _
      "End Date", "End Date")

    'Enters the start date in the document
    Selection.TypeText Text:=Format(StartDate, _
      "dddd, MMMM dd, yyyy")
    Selection.TypeText (vbCr & vbLf)

    'Determines the number of dates to print
    Repeats = DateDiff("d", StartDate, EndDate)

    'Loops to print the list of dates
    For i = 1 To Repeats
        ListDate = DateAdd("d", i, StartDate)
        Selection.TypeText Text:=Format(ListDate, _
          "dddd, MMMM dd, yyyy")
        Selection.TypeParagraph
    Next i
End Sub

The StartDate and EndDate variables, set by your input, determines how many times the For ... Next loop is repeated.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13155) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Generating a List of Dates.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Recovering Password-Protected Documents

Got a locked document you just need to get into? It may be quite easy (or next to impossible) using the ideas in this tip.

Discover More

Running a Macro in a Number of Workbooks

Got a macro that you need to run on each of a number of workbooks? Excel provides a number of ways to go about this task, ...

Discover More

Replacing Hidden Text

Word allows you to format text so it can be easily hidden from view and from printing. If you want to convert the hidden ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Processing Information Pasted from a PDF File

When pasting information copied from a PDF file, you can end up with a paragraph for each line of the original document. ...

Discover More

Talking to Yourself

Need to keep notes about a document, but you don't want others to see those notes either on-screen or on-paper? Here's an ...

Discover More

Transposing Two Characters

If you have two characters in the wrong order, you might be interested in a shortcut you can use to switch their order. ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 2?

2021-03-13 06:42:29

Ken Endacott

Here is a more user friendly version of the macro ListDates.

Sub ListDates()
Dim StartDate As Date
Dim EndDate As Date
Dim Repeats As Integer
Dim i As Long
Dim s As String

' date can be entered in one of the following formats:
' 1 feb 2021 1 February 21 1,Feb,21 1/2/2021 1/2/21
' 1,2,21 1,feb and others
s = InputBox("Please enter the starting date.", _
"Start Date", "Start Date")
If s = "" Then Exit Sub
If Not IsDate(s) Then
MsgBox "Error in start date"
Exit Sub
End If
StartDate = s

s = InputBox("Please enter the ending date.", _
"End Date", "End Date")
If s = "" Then Exit Sub
If Not IsDate(s) Then
MsgBox "Error in end date"
Exit Sub
End If
EndDate = s

'Determines the number of dates to print
Repeats = DateDiff("d", StartDate, EndDate) + 1

i = 1
Do While i <= Repeats
Selection.TypeText Text:=Format(StartDate, _
"dddd, MMMM dd, yyyy")
Selection.TypeParagraph
i = i + 1
StartDate = DateAdd("d", 1, StartDate)
Loop

End Sub


This Site

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.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.