Some users wish that Outlook can auto archive an Outlook item as soon as they assign a specific color category to it, such as “Archive” category. In this post, we will share you a method, which can take Outlook email as an example.
By default, you can only make Outlook to auto archive items on basis of the time intervals. However, in reality, many users even would like to auto archive items as per the color categories. For instance, when you apply a specific color category to an email, Outlook can archive it immediately. Though Outlook’s default functions cannot realize it, you still can use the following VBA code to achieve it with ease.
Auto Archive an Email when Assigning a Specific Color Category to It
- At the very outset, start your Outlook program.
- In the subsequent Outlook main screen, press “Alt + F11” keys.
- Then you will access the VBA editor, in which you need to find and open the “ThisOutlookSession” project.
- Next you could copy the following VBA code into this project window.
Public WithEvents objInspectors As Outlook.Inspectors Public WithEvents objExplorer As Outlook.Explorer Public WithEvents objMail As Outlook.MailItem Private Sub Application_Startup() Set objInspectors = Outlook.Application.Inspectors Set objExplorer = Outlook.Application.ActiveExplorer 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 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 objMail_PropertyChange(ByVal Name As String) Dim objCurrentFolder As Outlook.Folder Dim objArchivePSTFile As Outlook.Folder Dim objArchiveFolder As Outlook.Folder If Name = "Categories" Then 'If "Archive" Catgeory Is Assigned to This Email If InStr(objMail.Categories, "Archive") Then Set objCurrentFolder = objMail.parent 'Open the specific Archive Outlook PST File in Your Outlook Application.Session.AddStore "C:\Users\Test\Documents\Outlook Files\Archive.pst" Set objArchivePSTFile = Application.Session.folders("Archives") On Error Resume Next Set objArchiveFolder = objArchivePSTFile.folders(objCurrentFolder.Name) If objArchiveFolder Is Nothing Then Set objArchiveFolder = objArchivePSTFile.folders.Add(objCurrentFolder.Name) End If 'Archive This Email objMail.Move objArchiveFolder 'Remove the Archive PST File from Your Outlook Application.Session.RemoveStore objArchivePSTFile End If End If End Sub
- After that, you should sign this code.
- Next change your Outlook macro security settings to ensure signed macros are permitted.
- Finally you ought to restart your Outlook to activate this new macro.
- Since then, every time you assign the specific color category, like the “Archive” predefined in the above code, to an Outlook email, it will get archived to your preset Archive Outlook PST file.
Rescue Your PST Data after Crashes
To be honest, no program is powerful enough to avoid errors or crash. The same holds true for Outlook application. Therefore, for Outlook regular users, it is very difficult to block Outlook corruption. The more effective precaution is to get hold of a potent PST fix utility, such as DataNumen Outlook Repair. It can come to your rescue as soon as you encounter PST damage.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including sql recovery and outlook repair software products. For more information visit www.datanumen.com