Skip to main content

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 as following steps:

1. Press Alt + F11 keys to enable the Microsoft Visual Basic for Applications window

2. Double click at ThisOutlookSession from Project1 in left pane, then copy and paste below code to the right script.

VBA: Merge two folders without diplicates

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

doc merge folders without duplicates 1

3. Click Tools > References and in the popping dialog, check Microsoft Scripting Runtime checkbox.

doc merge folders without duplicates 2 doc arrow right doc merge folders without duplicates 3

4. Click OK. Now press F5 key to run the code. A dialog pops out to remind you 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).
doc merge folders without duplicates 4

5. Click OK, in the second popping dialog, choose the second folder you want to compare and merge with.
doc merge folders without duplicates 5

6. Click OK, now, all the items in the first folder will be moved to the second folder, and the duplicate ones are also removed.
doc merge folders without duplicates 6


Merge multiple folders and remove duplicate items with Kutools for Outlook

If you are not familiar with VBA code, try to use Kutools for Outlook, a handy add-in, with its Consolidating Folders and Duplicate Emails utilities which can easily and quickly handle this job.

Kutools for Outlook , Includes 100+ powerful features and tools for Microsoft Outlook 2016, 2013, 2010 and Office 365.

Free install Kutools for Outlook, and then do as below steps:

Merge multiple folders

1. Click Kutools Plus > Consolidating Folders, then in the Merge multiple folders into one dialog, click Add to add the folders into list which will be merged, choose a folder as the destination folder.
doc consolidate and remove duplicate 1

2. Click OK > OK. Now all the items in the selected folders have been merged into one specific folder.
doc consolidate and remove duplicate 2

Remove duplicate items

3. Click Kutools > Delete Duplicate > Duplicate Emails. Then in the Duplicate messages dialog, check the folder you want to remove duplicates.
doc consolidate and remove duplicate 3

4. Click Next, in Duplicate Messages Settings dialog, specify the criteria you use to compare emails, then check Delete duplicate messages option and select Compare for duplicate messages within a single folder.
doc consolidate and remove duplicate 4

5. Click Next > Next, the duplicate emails have been filtered. Click Delete duplicate message button > OK to remove the duplicate emails successfully.
doc consolidate and remove duplicate 5 doc merge folders without duplicates 6


Best Office Productivity Tools

Kutools for Outlook - Over 100 Powerful Features to Supercharge Your Outlook

πŸ€– AI Mail Assistant: Instant pro emails with AI magic--one-click to genius replies, perfect tone, multilingual mastery. Transform emailing effortlessly! ...

πŸ“§ Email Automation: Out of Office (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: Easily Recall Emails  /  Block Scam Emails by Subjects and Others  /  Delete Duplicate Emails  /  Advanced Search  /  Consolidate Folders ...

πŸ“ Attachments ProBatch Save  /  Batch Detach  /  Batch Compress  /  Auto Save   /  Auto Detach  /  Auto Compress ...

🌟 Interface Magic: 😊More Pretty and Cool Emojis   /  Boost Your Outlook Productivity with Tabbed Views  /  Minimize Outlook Instead of Closing ...

πŸ‘ One-click Wonders: Reply All with Incoming 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 ...

Over 100 Features Await Your Exploration! Click Here to Discover More.

Read More       Free Download      Purchase
 

 

Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations