Skip to content

Instantly share code, notes, and snippets.

@angusdev
Created January 27, 2022 01:00
Show Gist options
  • Save angusdev/79431d46338e9de8e88e313dc2d27ce7 to your computer and use it in GitHub Desktop.
Save angusdev/79431d46338e9de8e88e313dc2d27ce7 to your computer and use it in GitHub Desktop.
Option Explicit
Public Sub FindDuplicate()
Dim i As Long
Dim myOlItems As Outlook.Items
Dim myOlMailItem1, myOlMailItem2 As Outlook.mailItem
Set myOlItems = Application.ActiveExplorer.CurrentFolder.Items
myOlItems.Sort "ReceivedTime", True
i = 1
While i < 20000 And i < myOlItems.Count
If TypeName(myOlItems(i)) = "MailItem" And TypeName(myOlItems(i + 1)) = "MailItem" Then
Set myOlMailItem1 = myOlItems(i)
Set myOlMailItem2 = myOlItems(i + 1)
If myOlMailItem1.subject = myOlMailItem2.subject _
And myOlMailItem1.ReceivedTime = myOlMailItem2.ReceivedTime _
Then
ActiveExplorer.Activate
ActiveExplorer.ClearSelection
ActiveExplorer.AddToSelection myOlItems(i)
ActiveExplorer.AddToSelection myOlItems(i + 1)
Debug.Print myOlItems(i).ReceivedTime & " " & myOlItems(i).subject
i = 99999
End If
End If
i = i + 1
Wend
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment