If you always want to ensure that the latest date is inserted into the subject no matter when forwarding or replying an email, you can use the way introduced in this post. It will auto update the date that has existed in the subject to the current date.
By the means introduced in my previous article – “How to Auto Insert Current Date into the Subjects of Incoming Emails with Outlook VBA”, each incoming email’s subject will always contain a date. In this case, when you forward or reply this email, by default, the date will be kept in subject as well. However, at times, the existing date isn’t same as the date when you forward or reply. Thus, you may need to manually change the date. It may be troublesome. So, here we will expose a piece of VBA code, which will auto update the date no matter when forwarding or replying.
Auto Update the Date in Subject when Forwarding or Replying an Email
- To start with, launch your Outlook application.
- Then press “Alt + F11” key buttons in the main Outlook window.
- In the next “Microsoft Visual Basic for Applications” window, you ought to find and open the “ThisOutlookSession” project.
- Subsequently, copy and paste the following VBA code into this project.
Public WithEvents objExplorer As Outlook.Explorer Public WithEvents objInspectors As Outlook.Inspectors Public WithEvents objMail As Outlook.MailItem Private Sub Application_Startup() Set objExplorer = Outlook.Application.ActiveExplorer Set objInspectors = Outlook.Application.Inspectors End Sub Private Sub objExplorer_SelectionChange() On Error Resume Next If objExplorer.Selection.Item(1).Class = olMail Then Set objMail = objExplorer.Selection.Item(1) End If End Sub Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector) If Inspector.CurrentItem.Class = olMail Then Set objMail = Inspector.CurrentItem End If End Sub Private Sub objMail_Forward(ByVal Forward As Object, Cancel As Boolean) Forward.Subject = SubjectWithUpdatedDate(Forward.Subject) End Sub Private Sub objMail_Reply(ByVal Response As Object, Cancel As Boolean) Response.Subject = SubjectWithUpdatedDate(Response.Subject) End Sub Private Sub objMail_ReplyAll(ByVal Response As Object, Cancel As Boolean) Response.Subject = SubjectWithUpdatedDate(Response.Subject) End Sub Function SubjectWithUpdatedDate(ByVal strSubject As String) As String Dim objRegExp As RegExp Dim objMatchCollection As MatchCollection Dim objMatch As match Dim strDate, strToday As String Set objRegExp = New RegExp 'Format - "YYYY-MM-DD", such as "2017-06-02" objRegExp.Pattern = "\d\d\d\d-\d\d-\d\d" objRegExp.Global = True 'Check if there is already such a date in the email subject If objRegExp.Test(strSubject) Then Set objMatchCollection = objRegExp.Execute(strSubject) For Each objMatch In objMatchCollection strDate = objMatch.value strToday = Format(Date, "YYYY-MM-DD") 'If not same as today, replace it with today If strDate <> strToday Then SubjectWithUpdatedDate = Replace(strSubject, strDate, strToday) Else SubjectWithUpdatedDate = strSubject End If Next 'If not contain a date, insert the current date Else SubjectWithUpdatedDate = strSubject & " (" & Format(Date, "YYYY-MM-DD") & ")" End If End Function
- After that, you should sign this code.
- Later change your Outlook macro settings to enable digitally signed macros.
- Eventually, restart your Outlook application to activate the new VBA code.
- Now, you can have a try.
- Firstly, select an email.
- Then click “Reply”, “Reply All” or “Forward” button in the ribbon.
- At once, a new email will pop up, in which you can see that the date in its subject line has been updated to the current date.
If Confronted with Frequent Outlook Errors
It is inevitable that you will encounter various problems in Outlook, like abrupt restarting, sudden crash, and random PST errors and so on. Thereby, you have to keep a potent repair tool nearby, such as DataNumen Outlook Repair. It is able to fix PST errors and corruption within minutes and like a breeze.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupt mdf and outlook repair software products. For more information visit www.datanumen.com