Skip to content

Instantly share code, notes, and snippets.

@DataSolveProblems
Created June 29, 2019 12:36
Show Gist options
  • Save DataSolveProblems/f0ef7011fbb4c995636e46b5c5a4cc4e to your computer and use it in GitHub Desktop.
Save DataSolveProblems/f0ef7011fbb4c995636e46b5c5a4cc4e to your computer and use it in GitHub Desktop.
Sub SearchEmails()
Dim olNS As NameSpace
Dim FolderInbox As MAPIFolder
Dim filtered_items As Items
Dim olMail As MailItem
Dim strFilter As String
Set olNS = GetNamespace("MAPI")
Set FolderInbox = olNS.GetDefaultFolder(olFolderInbox)
'strFilter = "@SQL= urn:schemas:httpmail:subject LIKE '%<Subject>%'"
strFilter = "@SQL= urn:schemas:httpmail:textdescription LIKE '%<Email Body>%'"
Set filtered_items = FolderInbox.Items.Restrict(strFilter)
If filtered_items.Count = 0 Then
GoTo empty_objects
End If
For Each olMail In filtered_items
Debug.Print olMail.Subject
Debug.Print olMail.SenderEmailAddress
Next olMail
empty_objects:
Set FolderInbox = Nothing
Set olNS = Nothing
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment