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 www.datanumen.com

6 responses to “How to Insert a Future or Past Date in Your Word Document via VBA Codes”

  1. שאלה עם אני רוצה פשוט לעדכן תאריך במספרים זה אפשרי?
    הכוונה 04/08/2024 ולעדכן לשנה ל04/08/2025

  2. Oh my gosh this is great!! I haven’t ever done a macro so thank you for having the code and everything. I just KNEW there had to be a way to have a letter date to a future day (I have to send something out every Thursday but the due dates in the letter need to be Friday). I was even able to (just for funsies) do a negative day so it put yesterdays date in!! Clicking the develepor and macro tool each time I open it may seem tedious to some but the 3 clicks rather than typing the day and date every time…love the efficiency!! Thank you!!!

  3. Worked like a charm. I managed this for a ‘day+1’ date. However, when I reopened the file on another day, the date didn’t update automatically to the new day+1. Did I miss something or do I have to run the macro again every time I reopen the file?

Leave a Reply

Your email address will not be published. Required fields are marked *