A client had many duplicates in one folder and while there are a number of duplicate remover utilities, any of which work great if you need to check multiple folders for duplicates, he just needed to check one folder. He didn't want to install a utility but there were too many duplicates to manually remove them.
The solution: a macro that moves duplicate messages to a subfolder for review.
This macro is slow. If you have a lot of messages in the folder, expect it to take some time to run.
To use, select a folder that needs checked for duplicates and run the macro. The macro will create a subfolder named Duplicates and move the duplicate messages to it. After reviewing the duplicates, delete the folder.
Public Sub MoveDuplicates() Dim objOL As Outlook.Application Dim objFolder As Outlook.MAPIFolder Dim objDupFolder As Outlook.MAPIFolder Dim objDictionary As Object Dim i As Long Dim objItem As Object Dim strKey As String Set objOL = Outlook.Application Set objDictionary = CreateObject("scripting.dictionary") Set objFolder = objOL.ActiveExplorer.currentFolder On Error Resume Next Set objDupFolder = objFolder.Folders.Item("Duplicates") If objDupFolder Is Nothing Then Set objDupFolder = objFolder.Folders.Add("Duplicates") End If For i = objFolder.Items.count To 1 Step -1 Set objItem = objFolder.Items.Item(i) 'Only check email items type If InStr(1, objItem.MessageClass) <> "IPM.Schedule" Then strKey = objItem.Subject & "," & objItem.Body & "," & objItem.SentOn strKey = Replace(strKey, ", ", Chr(32)) If objDictionary.Exists(strKey) = True Then objItem.Move objDupFolder ' use this to delete immediately ' objItem.Delete Else objDictionary.Add strKey, True End If End If Next i End Sub
How to use the macros on this page
First: You need to have macro security set to the lowest setting, Enable all macros during testing. The macros will not work with the top two options that disable all macros or unsigned macros. You could choose the option Notification for all macros, then accept it each time you restart Outlook, however, because it's somewhat hard to sneak macros into Outlook (unlike in Word and Excel), allowing all macros is safe, especially during the testing phase. You can sign the macro when it is finished and change the macro security to notify.
To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, look at Tools, Macro Security.
After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
The macros on this page should be placed in a module.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
More information as well as screenshots are at How to use the VBA Editor