How to Insert a Future or Past Date in Your Word Document via VBA Codes

In this article, we will show you an interesting trick to insert a future or past date in your Word Document via VBA codes.

Generally, we have no difficulty in inserting a current date in our Word document. Yet, now and then, we could be preparing for the document needed next week or month or even later. Then here is the problem you can’t bypass. How can you insert a future date in Word file? And sometimes how about a past one even?

It is therefore we think you must grasp this useful method to better fulfill your work tasks.

Use VBA Codes to Insert a Future or Paste Date

  1. To begin with, open your Word document.
  2. Then, click “Developer” tab.
  3. Next click “Visual Basic” to open the VBA editor. If the “Developer” tab is not available in your Word Ribbon, you can press “Alt+ F11” to open the editor instead.Click "Developer" ->Click "Visual Basic"
  4. Now in the editor, click “Normal” on the left side.
  5. Then click “Insert” on the toolbar.
  6. Next, choose “Module” from the list-menu.Click "Normal" ->Click "Insert" ->Click "Module"
  7. Now double click the newly inserted module, and the editing area shall be available on the right side.
  8. Just paste the following codes there:
Sub InsertFutureOrPastDate()
  Dim strNumberOfDays As String

  ' Input the number of days you want to insert from today to the future or past date.
  strNumberOfDays = InputBox("Please input the number of days you want to insert", "future or past date", "Input here.For exemple,input 1 to insert the date of tomorrow")
  ' Insert the future or past date according to the inputed number of days
  If strNumberOfDays <> "" Then
    Selection.TypeText Text:=Format(Date + strNumberOfDays, "dddd, MMMM dd, yyyy")
  End If       
End Sub
  1. Next, click “Save” button and close the VBA editor.Double Click the New Module ->Paste Codes ->Click "Save"
  2. Now switch back to Word document screen and place your cursor at the place where the future or past date goes.
  3. Then click “Developer” tab again.
  4. And click “Macros” in “Code” group to open the “Macros” window. Again if the “Developer” tab is not displayed, you just need to press “Alt+ F8”.Click "Developer" ->Click "Macros"
  5. Now in “Macros” window, find and select the “InsertFutureOrPastDate” macro.
  6. Next click “Run”.Select "InsertFutureOrPastDate" ->Click "Run"
  7. Then you shall be greeted by a message box. You can enter a number in the text box at the bottom of the box to represent the days left to the future date. For example, if you want to insert the date of tomorrow, you should input “1” there. Likewise, if you need a past date, just add a minus sign before the value, such as “-1” for yesterday.
  8. Remember to click “OK”.Enter in the Text Box ->Click "OK"Insert a Future and Past Date

Note: In codes “Selection.TypeText Text:=Format(Date + strNumberOfDays, “dddd, MMMM dd, yyyy”)”, the “dddd, MMMM dd, yyyy” represent the date format where “M” stands for “month”, “d” for “day”, “y” for “year” and “dddd” for “week”, so you are free to change it as you like.

Regain Your Valuable Files

Word is susceptible to collapses which throws our Word files in danger. Now and then, some of our priceless data are just gone. But what’s gone is not completely gone. You can sit to lament over the loss of your critical files or you can choose a proficient damaged Word recovery tool to retrieve them.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including Excel xls file problem repair and pdf repair software products. For more information visit

Comments are closed.