Created
June 29, 2019 12:36
-
-
Save DataSolveProblems/f0ef7011fbb4c995636e46b5c5a4cc4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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