After color categorizing Outlook contacts, you may desire to create a specific contact group from the contacts in a specific category. This article will teach you a quick way to accomplish it with Outlook VBA.
“Color Categories” feature indeed plays a good role in classifying Outlook items, no matter mails, tasks, appointments or contacts. If you’ve assigned specific color categories to all your Outlook contacts, it is also advisable to gather the contacts which are in the same category, namely creating a specific contact group for them. As usual, if you want to achieve it, you have to firstly remember which contacts are in the same category and then manually create a group and add the contacts one by one. Without a doubt, it will be quite cumbersome and error prone. In fact, there is a faster method through Outlook VBA. Read on to get the detailed steps.
Create a New Contact Group from Contacts in a Specific Category
- At first, you ought to start Outlook and switch to “Developer” tab.
- Then press “Visual Basic” to access “Microsoft Visual Basic for Applications” window.
- Subsequently, you need to open a new module and copy the following VBA codes into it.
Sub CreateContactGroupforContactsinSpecificCategory() Dim olContactF As Folder Dim strCategory As String Dim olItems As Outlook.Items Dim obj As Object Dim olConGroup As DistListItem Dim olContact As Outlook.ContactItem Dim tempMail As MailItem Dim Recips As Recipients Set olContactF = Outlook.Application.Session.GetDefaultFolder(olFolderContacts) strCategory = InputBox("Enter the name of the specific category:") Set olItems = olContactF.Items.Restrict("[Categories] = '" & strCategory & "'") Set olConGroup = Application.CreateItem(olDistributionListItem) If olItems.Count > 0 Then For Each obj In olItems If TypeName(obj) = "ContactItem" Then Set olContact = obj Set tempMail = Application.CreateItem(olMailItem) tempMail.Recipients.Add (olContact.Email1Address) Set Recips = tempMail.Recipients With olConGroup .DLName = strCategory .AddMembers Recips 'Use ".Save" to directly save the new contact group .Display End With End If Next Else MsgBox ("There is no contacts in '" & strCategory & "'!") End If End Sub
- Next you can exit the “Visual Basic” window and add the new module to the Quick Access Toolbar as normal. Just follow the steps shown as the following screenshot:
- After that, you need change the macro settings to enable this macro.
- Finally you can hit the new macro button in Quick Access Toolbar.
- Firstly, you will be required to type the specific category’s name and hit “OK” button.
- At once a new contact group window will pop up. Then the group name will be the same as the name of the specific category.
Note: If there is no contact in the specific category, you will receive an Outlook alert, like the following screenshot:
Don’t Fear Outlook Errors!
Outlook is susceptible to errors. Hence if you are a regular Outlook user, suffering them must be a common and frequent occurrence. So why do you still fear them? It must because that you have no clear solutions in your mind about how to deal with them. Actually, you can try to dispose of them by starting Outlook in safe mode, creating a new Outlook profile, repairing office suite and taking recourse to a top-of-the-line corrupt Outlook PST repair tool, such as DataNumen Outlook Repair.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including repair corrupt mdf database and outlook repair software products. For more information visit www.datanumen.com