How to Auto Rename or Remove the Older Emails with the Same Subjects as the New Incoming Ones

Some people hope that Outlook can auto check the older emails’ subjects when new emails arrive, and rename or delete the older emails if they have the same subjects as the new emails. This demands using Outlook VBA. This article will help you achieve it.

You must have ever received many emails which have the same subjects. Is it a bit troublesome for you to identify and distinguish them in the email list? Or do you think that those older emails are exactly useless for you? If so, you must desire to let Outlook automatically scan and check all the existing emails when new emails arrive. When there are emails which have the same subjects as the new, Outlook can ask you whether to rename or delete them. With no doubts, Outlook doesn’t provide users with this kind of feature. Hence, you have to resort to VBA. Here we will expose the detailed codes and operations to you.

Auto Rename or Remove the Older Emails

  1. At first, you can start Outlook and head to the “Developer” tab.
  2. Then you will be able to find and click on the “Visual Basic” button.
  3. After hitting it, you will access the VBA editor window. In it, you will need to open “ThisOutlookSession” project.
  4. Next you ought to copy and paste the following VBA codes into it.
Public WithEvents olItems As Outlook.Items

Sub Application_Startup()
    'Specify the Emails in Inbox folder
    Set olItems = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub olItems_ItemAdd(ByVal Item As Object)
    Dim i As Long
    Dim objVariant As Variant
    Dim strMsg As String
    Dim nRes As Integer

    For i = 1 To olItems.Count
        Set objVariant = olItems.Item(i)
        If TypeOf objVariant Is MailItem Then
           If objVariant.Subject = Item.Subject And objVariant.ReceivedTime < Item.ReceivedTime Then
              nDateDiff = DateDiff("d", objVariant.ReceivedTime, Now)
              'Add "(Old)" suffix to the email subjects
              objVariant.Subject = objVariant.Subject & "(Old)"
              objVariant.Save
              'If the old emails have been recieved for 60 days, ask you whether to delete
              If nDateDiff > 60 Then
                 strMsg = "There are some older emails whcih have the same subjects with the new email and have been recieved for 2 months. Do you want to delete them?"
                 nRes = MsgBox(strMsg, vbExclamation + vbYesNo, "Find Older Emails")
                 If nRes = vbYes Then
                    objVariant.Delete
                 End If
              End If
           End If
        End If
    Next
End Sub

VBA Codes - Auto Rename or Remove the Older Emails with the Same Subjects as the New Incoming Ones

  1. Subsequently, you would be required to digitally sign this code. Hit “Tools” > “Digital Signature”. Then in the popup dialog box, you can select one existing certificate. If no readymade certificate, then you can use “Digital Certificates for VBA Projects” to create a new one.Sign the ThisOutlookSession Project
  2. After that, you can exit the current window and proceed to change the macro settings, permitting digitally signed macros only.
  3. Eventually, you can restart Outlook to activate the new macro. From now on, when new emails arrive in the Inbox, Outlook will auto check all the existing emails.
  • If the old emails have the same subject as the new, then Outlook will auto add “(Old)” suffix to the email subject.
  • And if the older emails have been stored in Inbox for over 2 months, then you will receive a prompt, asking you whether want to delete them, like the picture below. You can select “Yes” or “No” based on your own needs.Prompt Asking Whether to Delete the Older Emails

 Outlook File Corruption Due to Large Size

Some people have no the habits of deleting old items regularly in Outlook. Thus their Outlook file will be in large size, which is inadvisable exactly. It’s because an oversized Outlook file is far more vulnerable than file in small size. Once the file gets corrupted, the inbuilt repair tool, Scanpst.exe, will be helpless in most cases. Your unique resort may be a remarkable and well-proven corrupted Outlook PST repair tool, like DataNumen Outlook Repair.

Author Introduction:

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

Comments are closed.