There are several reasons why duplicate contacts might appear in your contact list.
While deleting these duplicates through import/export methods or manually is one approach, imagine having a one-click option to eliminate all duplicate contacts.
This is where the VBA code comes into play.
This blog post is dedicated to guiding you through the process of using VBA to clean up your duplicate contacts in Outlook, ensuring it remains streamlined and efficient.
VBA Code to Delete Duplicate Contacts
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objDict As Object
Dim objContact As Outlook.ContactItem
Dim i As Integer
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olFolderContacts)
Set objDict = CreateObject("Scripting.Dictionary")
For Each objContact In objFolder.Items
If objDict.Exists(objContact.Email1Address) Then
i = i + 1
objDict.Add objContact.Email1Address, True
MsgBox i & " duplicate contacts were deleted."
Adding VBA Code to Outlook
Now that you have a clear understanding of what needs to be done and you’ve obtained your VBA code, it’s time to learn the step-by-step method of integrating the VBA code into Outlook.
This guide will also cover how you can activate or enable the VBA code whenever you wish to perform the task.
Open Outlook Classic, and Press Alt + F11 to open the VBA editor. You can also click on the developer tab and click on Visual Basic under the Code section.
This is the designated area where you can insert the VBA code and save it.
Click on the insert tab, which will open the dropdown which consists of a few options, and select Modules.
Copy and Paste the Code: Enter the provided VBA script into the new module.
Save and Close: Save your work (Press
Ctrl + S) and exit the editor.
Step-by-Step Method for Using this VBA Code
- Access the VBA Editor: Press
Alt + F11in Outlook.
- Locate the Script: In the VBA editor, navigate to the module where you pasted the script.
- Execute the Script: Select the script and press
F5to run it.
- Confirmation: A message box will appear confirming the number of duplicates deleted.