How to Auto Apply the Same Color Category to All Members when Categorizing a Contact Group in Outlook

When you apply specific color categories to a contact group, if you want to assign the same categories to all the contacts corresponding to the group members, you could use the method introduced in this article.

Some users would like to apply the same color categories to the group members as they color categorizing a contact group. In general, to achieve it manually, you have to firstly find the corresponding contacts and then assign categories. It’ll be quite troublesome. Thus, here we’ll expose you a quicker way, which is using VBA code to auto realize it.

Auto Apply the Same Color Category to All Members when Categorizing a Contact Group in Outlook

Auto Apply the Same Color Category to All Members when Categorizing a Contact Group

  1. In the first place, start your Outlook application.
  2. Then switch to “Developer” and click on the “Visual Basic” button.
  3. Next you will get into Outlook VBA editor window in success.
  4. Subsequently, you ought to locate and double click the “ThisOutlookSession” project to open it.
  5. Later you need to copy and paste the VBA code below into this project.
Public WithEvents objExplorer As Outlook.Explorer
Public WithEvents objContactGroup As Outlook.DistListItem
Public objCurrentFolder As Outlook.Folder

Private Sub Application_Startup()
    Set objExplorer = Outlook.Application.ActiveExplorer
End Sub

Private Sub objExplorer_Activate()
    On Error Resume Next
    If TypeOf objExplorer.Selection.Item(1) Is DistListItem Then
       Set objContactGroup = objExplorer.Selection.Item(1)
    End If
 
    Set objCurrentFolder = objExplorer.CurrentFolder
End Sub

Private Sub objContactGroup_PropertyChange(ByVal Name As String)
    Dim strCategories As String
    Dim objCurrentFolderContacts As Outlook.Items
    Dim objDefaultFolderContacts As Outlook.Items
    Dim i As Long
    Dim objMemeber As Object
    Dim strFilter As String
    Dim objFoundContact As Outlook.ContactItem
 
    If Name = "Categories" Then
       'Get the categories of the selected contact group
       strCategories = objContactGroup.Categories
 
       'Find the contacts in the current folder and default "Contacts" folder
       Set objCurrentFolderContacts = objCurrentFolder.Items.Restrict("[Email1Address]>''")
       Set objDefaultFolderContacts = Application.Session.GetDefaultFolder(olFolderContacts).Items.Restrict("[Email1Address]>''")
 
       For i = objContactGroup.MemberCount To 1 Step -1
           'Find the contacts corresponding to the group members
           Set objMember = objContactGroup.GetMember(i)
 
           strFilter = "[Email1Address] = '" & objMember.Address & "'"
           Set objFoundContact = objCurrentFolderContacts.Find(strFilter)
 
           If objFoundContact Is Nothing Then
              Set objFoundContact = objDefaultFolderContacts.Find(strFilter)
           End If
 
           'Set the same categories to the contacts
           If Not (objFoundContact Is Nothing) Then
              objFoundContact.Categories = objFoundContact.Categories & ";" & strCategories
              objFoundContact.Save
           End If
      Next
    End If
End Sub

VBA Code - Auto Apply the Same Color Category to All Members when Categorizing a Contact Group

  1. After that, you need to sign this code.
  2. And then change your Outlook macro settings to permit the digitally signed macros.
  3. Finally you can restart your Outlook to activate the new VBA project.
  4. Now, you can have a try:
  • Firstly, assign a color category to a contact group in the explorer.Assign Color Category to Contact Group
  • Then the same color category will be set to the contacts corresponding to the group members, like the following screenshot:Group Member Has Same Color Category

Cope with Frequent Outlook Errors

Since Outlook is susceptible to errors and corruption, you should keep cautious of any abnormality in your Outlook, such as frequent freezing or not responding, random PST errors and so on. Moreover, so as to prevent PST data from loss, you have to back up your PST file regularly. In addition, it is highly recommended to prepare a reputable and well-proven PST repair utility, 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 corrupt sql and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.