Tuesday, November 2, 2021

Search emails dynamically for the past week

 Sub lastfewdays()

Dim olApp, olAccts, olInspect, ns As Object
Dim myStoreID, myEntryID As String

Set olApp = CreateObject("Outlook.Application")
Dim olFolder As outlook.MAPIFolder
Set ns = outlook.GetNamespace("MAPI")

lastWeek = Date - 7
strFind = "[ReceivedTime] >= '" & lastWeek & " 12:00 AM' AND [ReceivedTime] <= '" & Date & " 11:59 PM'"
MsgBox (strFind)
Set olFolder = ns.GetDefaultFolder(6)
Set filteritems = olFolder.Items.Restrict(strFind)

MsgBox (filteritems.count)

For Each citem In filteritems

Next citem



End Sub

No comments:

Post a Comment