Link to home
Start Free TrialLog in
Avatar of jana
janaFlag for United States of America

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
Avatar of jana
jana
Flag of United States of America image

ASKER

Avatar of Chris Bottomley
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
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

Open in new window

Avatar of jana

ASKER

i included the link, see ID 36978545.  we just want to display based on dates range
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jana

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)


Avatar of jana

ASKER

Ooops! for specific day, we meant (10/16/11 - 10/16/11)
Avatar of jana

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""?

Avatar of jana

ASKER

maybe only filtering only receipt dates instead of both?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jana

ASKER

Thanx