Search by date macro

Bamerand

Member
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server
I was able to locate this code at www.slipstick.com URL and I need slightly to amend it: what I need that the macro search for emails from one single specific email account and on specific date, such as for example yesterday, or 2 days ago or 1 week ago. Can you please give me a hand and give me some hints on how this can be achieved?

Sub SearchByAddress()
Dim myOlApp As New Outlook.Application
Dim NS As Outlook.NameSpace
Dim strFilter As String
Dim oMail As Outlook.MailItem

Set NS = myOlApp.GetNamespace("MAPI")

Set oMail = Application.ActiveExplorer.Selection.Item(1)
strFilter = oMail.senderName

Set myOlApp.ActiveExplorer.CurrentFolder = NS.GetDefaultFolder(olFolderInbox)
txtSearch = "from:(" & Chr(34) & strFilter & Chr(34) & ") OR to:(" & Chr(34) & strFilter & Chr(34) & ")"
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders

Set myOlApp = Nothing

End Sub
 
Top