How to Auto Assign a Color Category to New Appointments via Outlook VBA

Many users prefer to manage Outlook appointments by “Color Category” . So they hope that Outlook can auto categorize new appointments. This article will introduce how to realize it.

The article “How to Auto Categorize Appointments in Outlook Calendar” introduces a workaround. It uses Conditional Formatting to color code the appointments. Actually it just assigns a color to the item, not uses color category. Besides, Conditional Formatting relies on view settings. That is to say, if you create a conditional formatting rule in the current view, in another view, the rule will be invalid. So it is a get it.

Auto Assign a Color Category to New Appointments

  1. At first, switch to “Developer” tab and click the “Visual Basic” button.Visual Basic Button
  2. In the new window, open the “ThisOutlookSession” project by double clicking it.
  3. Then in the “ThisOutlookSession” dialog box, you should copy and paste the following VBA codes:
Public WithEvents olItems As Outlook.Items

Sub Application_Startup()
    Set olItems = Session.GetDefaultFolder(olFolderCalendar).Items
End Sub

Private Sub olItems_ItemAdd(ByVal Item As Object)
    Dim NewAppt As Outlook.AppointmentItem
 
    If Item.Class = olAppointment Then
       Set NewAppt = Item
    'Specify a color category based on appointment subject
    'You can replace "Test" with your desired string in subject line
       If InStr(Item.Subject, "Test") > 0 Then
          If Item.Categories = "" Then
             Item.Categories = "Test Category"
             Item.Save
          End If
       End If
    End If

    Set NewAppt = Nothing
End Sub

Copy & Paste the VBA Codes in ThisOutlookSession

 

  1. After that, click the “Save” icon in the toolbar.
  2. Later, you should sign this code and change the macro settings. As for how, you can see the Step 2 in the article “2 Steps to Auto Mark Junk Emails as Read in Outlook”.
  3. Finally you can have a try. The results will look like the following image:Auto Assign Color Category to the New Appointments

Beware of Malicious Macros in Outlook

There are a lot of dangerous macros. So we should only use digitally signed macros. And, nowadays, viruses in emails become more and more common. They are usually disguised as innocuous objects in the emails. Once we open, click or download them, our Outlook will get infected and then data will be corrupt. It is hard to recover damaged Outlook. So at this point, we have no choice but to use third party repair tools.

Author Introduction:

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

One response to “How to Auto Assign a Color Category to New Appointments via Outlook VBA”

Leave a Reply

Your email address will not be published. Required fields are marked *