How to Auto Insert Current Date into the Subjects of Incoming Emails with Outlook VBA

If you always want to insert the current date into the subjects of incoming emails as they land into your local mailbox, you can utilize the VBA code introduced in this post.

Auto Insert Current Date into the Subjects of Incoming Emails with Outlook VBAMy previous article “How to Auto Insert Current Date or Time into Email Subject or Body with Outlook VBA” has taught you to insert the current date into email subject when you’re composing an email. Similarly, many users wish that Outlook can auto insert the current date into the subject of incoming email as they arrive in their local mailbox. In response to this wish, we’ll introduce another way in the followings.

Auto Insert Current Date into the Subjects of Incoming Emails

  1. In the first place, start your Outlook application.
  2. Then in the main Outlook window, press “Alt + F11” key shortcuts.
  3. Next you will enter Outlook VBA editor window.
  4. Now you should open an empty module or insert a new one directly.
  5. Subsequently, copy and paste the following VBA code into such a module.
Sub InsertCurrentDateintoIncomingEmailSubjects(objMail As Outlook.MailItem)
    Dim strSubject As String
    Dim objRegExp As RegExp
    Dim objMatchCollection As MatchCollection
    Dim objMatch As match
    Dim strOriginalDate, strCurrentDate As String

    Set objRegExp = New RegExp
    'Date in the format - "YYYY-MM-DD", such as "2017-06-01"
    objRegExp.Pattern = "\d\d\d\d-\d\d-\d\d"
    objRegExp.Global = True
    'Check if the incoming email contains a date in "YYYY-MM-DD" format
    If objRegExp.Test(objMail.Subject) Then
       Set objMatchCollection = objRegExp.Execute(objMail.Subject)
       For Each objMatch In objMatchCollection

           strOriginalDate = objMatch.value
           strCurrentDate = Format(Date, "YYYY-MM-DD")
           'Check if the date is same as current date
           'if not same, replace the date with current date
           If strOriginalDate <> strCurrentDate Then
              objMail.Subject = Replace(objMail.Subject, strOriginalDate, strCurrentDate)
              'if same, keep it
              objMail.Subject = objMail.Subject
           End If
    'If not contain, insert the current date
       objMail.Subject = objMail.Subject & " (" & Format(Date, "YYYY-MM-DD") & ")"
 End If
 'Save the changes on the Mail
End Sub

VBA Code - Auto Insert Current Date into the Subjects of Incoming Emails

  1. After that, you should sign this code and change your Outlook macro settings to allow signed macros.
  2. Later you should exit the VBA editor window.
  3. Then go to “File” menu and click on the “Manage Rules & Alerts” button.
  4. In the new dialog box, click on “New Rule”.
  5. Next in “Rule Wizard” screen, choose “Apply rule on messages I receive” and hit “Next”.
  6. In the subsequent screen, set conditions as per your needs and hit “Next”.
  7. After that, in “Actions” screen, select “run a script” and select the new script and click “OK” > “Next”.Run Script in Rule
  8. And then specify or ignore exception, and click “Next”.
  9. Lastly name the new rule. Now you will get a new rule like the image below:Rule Details
  10. From now on, Outlook will auto insert the current date in the subjects of new emails as they arrive, shown as the following screenshot:Date Inserted in Email Subject

Outlook Errors Can Occur From Time to Time

Although Outlook provides users with a variety of features, it still cannot get rid of errors. In other words, you’ll encounter troubles in your Outlook now and then, such as sudden restarting or popup error messages and so on. To fix these issues, one of the best and more effective ways is to keep a preeminent repair tool handy, like DataNumen Outlook Repair. It is able to fix PST errors or corruption without breaking a sweat.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including repair mdf and outlook repair software products. For more information visit

Comments are closed.