jana
asked on
How to correctly use dates search in an Excel VBA exporting data from Outlook 2007
We have an excel that searches the entire Inbox and its sub-folder for specific phrases.
We would like to incorporate to the VBA script an efficient way to search for RECEIVINGS and SENT dates.
For example to only display emails SENT and RECEIVED between: 10/11/11 thru 10/16/11.
Whats the best of going about it.
Please see Excel attached
We would like to incorporate to the VBA script an efficient way to search for RECEIVINGS and SENT dates.
For example to only display emails SENT and RECEIVED between: 10/11/11 thru 10/16/11.
Whats the best of going about it.
Please see Excel attached
You say you have code so presumably you are happy to edit it ... but if not post it up and we can modify it:
Two subs one for each. The efficiency comes from the filter which in the scenario I have left at 100 days ago at 10am to 'today' at 11am.
It should be changed to remove the add ... I left it there so you can see how to move the dates about.
Chris
Two subs one for each. The efficiency comes from the filter which in the scenario I have left at 100 days ago at 10am to 'today' at 11am.
It should be changed to remove the add ... I left it there so you can see how to move the dates about.
Chris
Sub receivedMailWindow()
Dim fldr As Variant
Dim strFilter As String
Dim olkmailitems As Object
Dim olkMessage As Object
Set fldr = olkApp.Session.GetDefaultFolder(6) 'olFolderInbox
strFilter = "[ReceivedTime] >= '" & Format(DateAdd("d", -100, Date) + TimeSerial(10, 0, 0), "ddddd h:nn AMPM") & "'" & " and " & "[ReceivedTime] < '" & Format(Date + TimeSerial(11, 0, 0), "ddddd h:nn AMPM") & "'"
Set olkmailitems = fldr.Items.Restrict(strFilter)
For Each olkMessage In olkmailitems
Debug.Print olkMessage.Subject
Next
MsgBox "Done"
End Sub
Sub sentMailWindow()
Dim fldr As Variant
Dim strFilter As String
Dim olkmailitems As Object
Dim olkMessage As Object
Set fldr = olkAPP.Session.GetDefaultFolder(5) 'olFolderSentMail
strFilter = "[SentON] >= '" & Format(DateAdd("d", -100, Date) + TimeSerial(10, 0, 0), "ddddd h:nn AMPM") & "'" & " and " & "[ReceivedTime] < '" & Format(Date + TimeSerial(11, 0, 0), "ddddd h:nn AMPM") & "'"
Set olkmailitems = fldr.Items.Restrict(strFilter)
For Each olkMessage In olkmailitems
Debug.Print olkMessage.Subject
Next
MsgBox "Done"
End Sub
ASKER
i included the link, see ID 36978545. we just want to display based on dates range
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Will try when get back home. But reading your post I don't quite understand.
Anyways, just to make sure what we are trying to: we would like to modify the VBA to export, using a filter format of FROM/TO for a specific week (10/10/11 - 10/16/11), a specific day (10/10/11 - 10/16/11) or specific year (01/01/11 - 12/31/11)
Anyways, just to make sure what we are trying to: we would like to modify the VBA to export, using a filter format of FROM/TO for a specific week (10/10/11 - 10/16/11), a specific day (10/10/11 - 10/16/11) or specific year (01/01/11 - 12/31/11)
ASKER
Ooops! for specific day, we meant (10/16/11 - 10/16/11)
ASKER
just checked it.
We assume that we have to enter dates where ""ddddd h:nn AMPM"" is located?
Whats the format for:
specific week (10/10/11 - 10/16/11)
a specific day (10/16/11 - 10/16/11)
specific year (01/01/11 - 12/31/11)
is it ""101011 h:nn AMPM""?
We assume that we have to enter dates where ""ddddd h:nn AMPM"" is located?
Whats the format for:
specific week (10/10/11 - 10/16/11)
a specific day (10/16/11 - 10/16/11)
specific year (01/01/11 - 12/31/11)
is it ""101011 h:nn AMPM""?
ASKER
maybe only filtering only receipt dates instead of both?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx
ASKER
GetEmailDataToExcel-mod2.xlsm