When a new email arrives in your mailbox, if you want to quickly find out the old emails with same subject and apply the color categories of the found emails to this new email, you can use the piece of VBA code shared in this article.
So as to better classify and manage a great number of emails, you may be used to color categorizing emails. In this case, you must hope that Outlook can auto color categorize incoming emails based on your desired criteria, such as categorizing new email on basis of the color categories of old emails with same subject. In the followings, we will show how to achieve it with VBA.
Auto Categorize New Emails Based on the Categories of Old Emails with Same Subject
- At the very outset, you need to launch your Outlook application.
- Then, press “Alt + F11” keys, which will bring you to VBA editor window.
- Next, in the new “Microsoft Visual Basic for Applications” window, you ought to open the “ThisOutlookSession” project.
- Subsequently, copy and paste the following VBA code into this project.
Private objInbox As Outlook.Folder Private WithEvents objItems As Outlook.Items Private Sub Application_Startup() Set objInbox = Application.Session.GetDefaultFolder(olFolderInbox) Set objItems = objInbox.Items End Sub 'Occurs when a new mail arrives in mailbox Private Sub objItems_ItemAdd(ByVal Item As Object) Dim objMail As Outlook.MailItem Dim i As Long Dim objVariant As Variant If TypeOf Item Is MailItem Then Set objMail = Item For i = objInbox.Items.count To 1 Step -1 Set objVariant = objInbox.Items.Item(i) If objVariant.Class = olMail Then 'Find the older emails with same subject If objVariant.Subject = objMail.Subject And objVariant.SentOn < objMail.SentOn Then 'Assign the color categories of found emails to this new mail objMail.Categories = objVariant.Categories & ";" & objMail.Categories objMail.Save End If End If Next End If End Sub
- After that, you have to assign a digital certificate to this new VBA project.
- Later, exit the VBA editor window.
- Then, head to “File” > “Options” > “Trust Center” > “Trust Center Settings” > “Macro Settings” to enable digitally signed macros.
- Finally, you can restart your Outlook, which will activate the new macro.
- Since then, every time when a new email gets into your Inbox, Outlook will automatically search the older emails with the same subject and apply their color categories to this new email.
Rescue PST Data in Time
It is recognized that Outlook has a large amount of excellent capabilities. Yet, it is still unable to be immune from errors and crash. Thus, in order to repair Outlook in time, Outlook comes endowed with a built-in repair tool. But, if the damage is pretty extreme, it still can’t make effects. At that point, you have to employ a third party repair tool like DataNumen Outlook Repair. This tool is capable of scanning the corrupted PST files and restoring maximum data to its utmost.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including mdf repair and outlook repair software products. For more information visit www.datanumen.com