How to merge two folders without duplicates into one folder in Outlook?
In Outlook, you may have many email accounts with many folders, in some cases, you want to merge two folders into one and remove the duplicate items. How can you quickly solve this job? In this article, I introduce a VBA code to help you handle it as quickly as possible in Outlook.
Merge two folders without duplicates into one by VBA code
Merge multiple folders and remove duplicate items with Kutools for Outlook
Merge two folders without duplicates into one by VBA code
To merge two folders into one and remove the duplicate items, you can handle it with VBA code by following these steps:
1. Press "Alt + F11" keys to open the "Microsoft Visual Basic for Applications" window.
2. Double-click "ThisOutlookSession" from "Project1" in the left pane, then copy and paste the below code into the right script window.
VBA: Merge two folders without duplicates
Sub MergeOutlookFolders_WithoutDuplicates()
'UpdatebyExtendoffice20180521
Dim xSourceFolder As Outlook.Folder
Dim xTargetFolder As Outlook.Folder
Dim xCount, i As Long
Dim xItem As Object
Dim xSourceItem As Object
Dim xTargetItem As Object
Dim xDictionary As Scripting.Dictionary 'Object
Dim xStr As String
On Error Resume Next
Set xDictionary = New Scripting.Dictionary
Set xSourceFolder = Application.Session.PickFolder
Set xTargetFolder = Application.Session.PickFolder
xCount = 0
If xSourceFolder.DefaultItemType <> xTargetFolder.DefaultItemType Then
MsgBox "Error: The two folders are not in same type!", vbExclamation + vbOKOnly, "Kutools for Outlook"
Exit Sub
End If
For i = xSourceFolder.Items.Count To 1 Step -1
Set xSourceItem = xSourceFolder.Items.Item(i)
xSourceItem.Move xTargetFolder
Next
For i = xTargetFolder.Items.Count To 1 Step -1
Set xTargetItem = xTargetFolder.Items.Item(i)
Select Case xTargetItem.Class
Case olMail
With xTargetItem
xStr = .Subject & .Body & .SentOn
End With
Case olAppointment
With xTargetItem
xStr = .Subject & .Start & .Duration & .Location & .Body
End With
Case olContact
With xTargetItem
xStr = .FullName & .Email1Address & .Email2Address & .Email3Address
End With
Case olTask
With xTargetItem
xStr = .Subject & .StartDate & .DueDate & .Body
End With
End Select
If xDictionary.Exists(xStr) = True Then
xTargetItem.Delete
xCount = xCount + 1
Else
xDictionary.Add xStr, True
End If
Next i
If xCount <> 0 Then
MsgBox xCount & " duplicates removed when merging!", vbInformation + vbOKOnly, "Kutools for Outlook"
End If
End Sub
3. Click "Tools" > "References", and in the pop-up dialog, check the "Microsoft Scripting Runtime" checkbox.
![]() | ![]() | ![]() |
4. Click "OK". Now press the "F5" key to run the code. A dialog will pop out reminding you to select the first folder you want to merge (note: all the items in the first folder will be removed after merging with the second folder).
5. Click "OK". In the second pop-up dialog, choose the second folder you want to compare and merge with.
6. Click "OK". Now, all the items in the first folder will be moved to the second folder, and the duplicate ones will be removed.
Merge multiple folders and remove duplicate items with Kutools for Outlook
If you are not familiar with VBA code, try using "Kutools for Outlook", a handy add-in, with its "Consolidating Folders" and "Duplicate Emails" utilities, which can easily and quickly handle this task.
Say goodbye to Outlook inefficiency! Kutools for Outlook makes batch email processing easier - now with free AI-powered features! Download Kutools for Outlook Now!!
Merge multiple folders
1. Click "Kutools Plus" > "Consolidating Folders", then in the "Merge multiple folders into one" dialog, click "Add" to add the folders you want to merge into the list, and choose a folder as the destination folder.
2. Click "OK" > "OK". Now all the items in the selected folders have been merged into the specified folder.
Remove duplicate items
3. Click "Kutools" > "Delete Duplicate" > "Duplicate Emails". Then in the "Duplicate messages" dialog, check the folder where you want to remove duplicates.
4. Click "Next". In the "Duplicate Messages Settings" dialog, specify the criteria you will use to compare emails. Then check the "Delete duplicate messages" option and select "Compare for duplicate messages within a single folder".
5. Click "Next" > "Next", and the duplicate emails will be filtered. Click the "Delete duplicate message" button > "OK" to remove the duplicate emails successfully.
Best Office Productivity Tools
Breaking News: Kutools for Outlook Launches Free Version!
Experience the all-new Kutools for Outlook with 100+ incredible features! Click to download now!
π€ Kutools AI : Uses advanced AI technology to handle emails effortlessly, including replying, summarizing, optimizing, extending, translating, and composing emails.
π§ Email Automation: Auto Reply (Available for POP and IMAP) / Schedule Send Emails / Auto CC/BCC by Rules When Sending Email / Auto Forward (Advanced Rules) / Auto Add Greeting / Automatically Split Multi-Recipient Emails into Individual Messages ...
π¨ Email Management: Recall Emails / Block Scam Emails by Subjects and Others / Delete Duplicate Emails / Advanced Search / Consolidate Folders ...
π Attachments Pro: Batch Save / Batch Detach / Batch Compress / Auto Save / Auto Detach / Auto Compress ...
π Interface Magic: πMore Pretty and Cool Emojis / Remind you when important emails come / Minimize Outlook Instead of Closing ...
π One-click Wonders: Reply All with Attachments / Anti-Phishing Emails / πShow Sender's Time Zone ...
π©πΌβπ€βπ©π» Contacts & Calendar: Batch Add Contacts From Selected Emails / Split a Contact Group to Individual Groups / Remove Birthday Reminders ...
Use Kutools in your preferred language β supports English, Spanish, German, French, Chinese, and 40+ others!

