How to Prevent Assigning a Specific Category to Unsuitable Emails in Outlook

Some users complain that they always assign color categories to unsuitable mails in Outlook. Focused on this issue, this article will introduce a solution which uses VBA.

If you prefer to assign color categories manually in Outlook, it is nearly inevitable that you may color categorize items incorrectly by accident at times. Also, maybe you don’t realize this mistake until a long time later. For instance, you’ve created a specific color category named “Test”, which is specifically for those test emails. However, you often assign it to the emails which are not test ones. Without any doubts, this case, to some extent, may clutter up your emails, making your email management more troublesome. So, the followings will look at this issue to offer you an effective solution – use VBA to prevent you from assigning a specific color category to unsuitable emails.

Prevent Assigning a Specific Category to Unsuitable Emails in Outlook

Prevent Assigning a Specific Category to Unsuitable Emails

  1. At the very outset, launch your Outlook normally.
  2. Then press “Alt + F11” key buttons.
  3. Next in the VBA editor window, you need to open the “ThisOutlookSession” project.
  4. Subsequently, copy the following VBA codes into this project window.
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_Activate()
    On Error Resume Next
    Set objMail = objExplorer.Selection.Item(1)
End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
    On Error Resume Next
    Set objMail = Inspector.CurrentItem
End Sub

Private Sub objMail_PropertyChange(ByVal Name As String)
    Dim strSpecificCategory As String
    Dim strCategories As String
    Dim strPrompt As String
    Dim nWarning As Integer
    Dim varArray As Variant
    Dim i As Long
 
    'Change the specific category name to your real case
    strSpecificCategory = "Test"
 
    If Name = "Categories" Then
       'Specify the specific emails
       'You can change the conditions as per your needs
       If InStr(LCase(objMail.Subject), "test") <= 0 Then
          strCategories = objMail.Categories
          If InStr(strCategories, strSpecificCategory) > 0 Then
             'Display a warning
             strPrompt = "This is not a test mail. You should not assign " & Chr(34) & strSpecificCategory & Chr(34) & " category to this email."
             nWarning = MsgBox(strPrompt, vbExclamation + vbOKOnly, "Wrong Category Assignment")
             'Remove the specific category
             'Get the color categories array of this email
             varArray = Split(objMail.Categories, ",")
             'Check if the selected email has categories
             If UBound(varArray) >= 0 Then
                For i = 0 To UBound(varArray)
                    'Check if the email has the specific category
                    If Trim(varArray(i)) = strSpecificCategory Then
                       'Remove the specific categories
                       varArray(i) = ""
                       'Rebuild the categories
                       objMail.Categories = Join(varArray, ",")
                       Exit Sub
                    End If
                Next i
            End If
          End If
       End If
    End If
End Sub

VBA Codes - Prevent Assigning a Specific Category to Unsuitable Emails

  1. After that, sign this code.
  2. Later change your Outlook macro settings to permit the signed macros.
  3. Eventually restart Outlook to activate the new macro and take a try. When you assign the specific color category to the unsuitable emails, you will get a warning, like the following image:Warning

Cope with Frustrating PST Errors

Since PST file is susceptible to errors and corruptions, you had better prepare a potent Outlook repair tool in advance, such as DataNumen Outlook Repair. You’d better not entirely rely on the inbox repair tool in that it can only resolve small issues. Of course, if you have held the current data backups in hand, repair tool is unnecessary as well.

Author Introduction:

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

Leave a Reply

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