If you find that there are multiple duplicate items in your Outlook, you must want to quickly delete them. This article will teach you to use VBA to make a free Outlook duplicate remover.
Sometime, it’s inevitable that your Outlook may contain duplicate items. Not only will these duplicate items clutter up your mailbox, but also they’ll increase your mailbox size, which can make your PST file more vulnerable. Therefore, you had better delete them as soon as you realized this. However, without any doubts, it will be rather cumbersome if you try to remove them one by one manually.
Actually, in my previous article – “How to Quickly Remove the Duplicate Outlook Items in a Folder via VBA”, I have introduced how to use VBA to remove duplicate items in one folder. Therefore, you can make an Outlook duplicate remover by referring to the code in that post and looping through all folders recursively. In the followings, we will expose you the elaborate steps and VBA code.
Make a Free Outlook Duplicate Remover
- At the very outset, launch your Outlook application.
- Then press “Alt + F11” key shortcuts to access VBA editor.
- Next in the “Microsoft Visual Basic for Applications” window, open a module that is not in use.
- Subsequently, copy the following VBA codes into it.
Private Sub GetAllFolders() Dim objFolders As Outlook.Folders Dim objFolder As Outlook.Folder 'Get all the folders in a specific PST file Set objFolders = Outlook.Application.Session.Folders("John Smith").Folders For Each objFolder In objFolders Call RemoveDuplicateItems(objFolder) Next End Sub Sub RemoveDuplicateItems(objCurrentfolder As Outlook.Folder) Dim objDictionary As Object Dim i As Long Dim objItem As Object Dim strKey As String Dim objSubfolder As Folder Set objDictionary = CreateObject("scripting.dictionary") On Error Resume Next For i = objCurrentfolder.Items.Count To 1 Step -1 Set objItem = objCurrentfolder.Items.Item(i) Select Case objItem.Class 'Check email subject, body and sent time Case olMail strKey = objItem.Subject & "," & objItem.Body & "," & objItem.SentOn 'Check appointment subject, start time, duration, location and body Case olAppointment strKey = objItem.Subject & "," & objItem.Start & "," & objItem.Duration & "," & objItem.Location & "," & objItem.Body 'Check contact full name and email address Case olContact strKey = objItem.FullName & "," & objItem.Email1Address & "," & objItem.Email2Address & "," & objItem.Email3Address 'Check task subject, start date, due date and body Case olTask strKey = objItem.Subject & "," & objItem.StartDate & "," & objItem.DueDate & "," & objItem.Body End Select strKey = Replace(strKey, ", ", Chr(32)) 'Remove the duplicate items If objDictionary.Exists(strKey) = True Then objItem.Delete Else objDictionary.Add strKey, True End If Next i If objCurrentfolder.Folders.Count > 0 Then For Each objSubfolder In objCurrentfolder.Folders Call RemoveDuplicateItems(objSubfolder) Next End If End Sub
- After that, you need to confirm that your macro security level to low.
- Finally you can run this code.
- First, in VBA editor, click into the “GetAllFolders” subroutine.
- Then press F5 key button to run this macro.
- When the macro finishes, all the duplicate items in your Outlook will be remove completely.
Resist Vexing PST Troubles
In order to protect your PST data against corruption or loss, you have to make a lot of precautions to combat against the occasional PST issues. Firstly, you have to make regular data backups. Secondly, you need to keep a potent PST repair tool handy, like DataNumen Outlook Repair. Thirdly, you have to pay attention to your daily handling with your Outlook, such as keeping closing Outlook properly, etc.
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