Tuesday, November 2, 2021

Filtering emails using DASL query in outlook using vba

 Sub lastfewdaysusingdslquery()

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'"
strFind = "@SQL=" & Chr(34) _
& "urn:schemas:httpmail:subject" & Chr(34) _
& " = 'hello'"
MsgBox (strFind)
Set olFolder = ns.Folders("allsourav@hotmail.com").Folders("Inbox")
Set filteritems = olFolder.Items.Restrict(strFind)

MsgBox (filteritems.count)

For Each citem In filteritems

Next citem



End Sub

No comments:

Post a Comment