How to Quickly Remove Duplicate Recipients from Your Outlook Email with VBA

If you add contact groups to the “To” field of the current email, there may be some duplicate ones among them. This article will teach you how to use VBA to quickly remove the duplicate recipients.

When composing an email, if you not only add contacts but also contact groups as recipients, sometimes, there may be some duplicated recipients as the contact groups are collapsed by default. In this case, if you want to find out the duplicate ones, you have to firstly expand the contact groups and then compare recipients manually, which has been introduced elaborately in my previous article– “How to Remove Duplicate Recipients from Your Outlook Emails”. Without any doubts, it’s very tedious. So, many users long for a quick way to remove duplicate recipients. In the followings, we will teach you to get it with Outlook VBA.

Quickly Remove Duplicate Recipients from Your Outlook Email with VBA

Quickly Remove Duplicate Recipients in Your Outlook Email

  1. In the first place, launch your Outlook application.
  2. Then switch to “Developer” tab and click on the “Visual Basic” button or just press “Alt + F11” keys.
  3. Next in the “Microsoft Visual Basic for Applications” window, you could open a blank module.
  4. Subsequently, copy and paste the following VBA codes into this module.
Sub RemoveDuplicateRecipients()
    Dim objCurrentMail As MailItem
    Dim objRecipients As Recipients
    Dim ContactGroupFound As Boolean
    Dim i, n As Long
 
    Set objCurrentMail = ActiveInspector.CurrentItem
    ContactGroupFound = True
 
    While ContactGroupFound = True
          Set objRecipients = objCurrentMail.Recipients
          ContactGroupFound = False
 
          'Expand the contact groups in "To" field
          For i = objRecipients.Count To 1 Step -1
              If objRecipients(i).AddressEntry.DisplayType <> olUser Then
                 For n = 1 To objRecipients(i).AddressEntry.Members.Count
                     If objRecipients(i).AddressEntry.Members.Item(n).DisplayType = olUser Then
                        objCurrentMail.Recipients.Add (objRecipients(i).AddressEntry.Members.Item(n).Address)
                     Else
                        objCurrentMail.Recipients.Add (objRecipients(i).AddressEntry.Members.Item(n).Name)
                        ContactGroupFound = True
                     End If
                 Next
                 objRecipients(i).Delete
              End If
          Next i
          objRecipients.ResolveAll
    Wend
 
    'Remove the duplicate recipients
    For i = objRecipients.Count To 1 Step -1
        For n = (i - 1) To 1 Step -1
            If objRecipients(i).Address = objRecipients(n).Address Then
               objRecipients(i).Delete
               Exit For
            End If
        Next
    Next
End Sub

VBA Code - Remove Duplicate Recipients from Your Outlook Email

  1. After that, you can add the new VBA project in the Quick Access Toolbar of message window.
  2. Later you need to set your Outlook macro security level to low.
  3. Finally you can have a try.
  • First, just compose an email as usual.
  • Then add contact groups and contacts in “To” field.
  • Next you can click the new macro button in Quick Access Toolbar.
  • At once, Outlook will automatically expand the contact groups and then remove the duplicate recipients.

Safeguard Your Valuable Outlook Data

As Outlook is prone to crash, your Outlook data is susceptible to corruption. So, you have to make a lot of efforts to protect your Outlook file. First of all, you need to back up your PST file on a regular basis. It will facilitate corrupt PST repair. In addition, you had better prepare a powerful fix tool handy, such as 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 mdf fix and outlook repair software products. For more information visit www.datanumen.com

One response to “How to Quickly Remove Duplicate Recipients from Your Outlook Email with VBA”

Leave a Reply

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