• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Can we derive count of e-mails for particuar dates ?

ThrottleWorks

Excel Ninja
Hi,

Can we derive count of e-mails in a folder using date as criteria.
For example, I have a folder 'Chandoo' in my Outlook.
I need a count of e-mails in Chandoo for e-mails received between today and last three working days.

Is it possible, can anyone please help me in this.
 
I think you should be able to check TypeName() of items in folder equal to "MailItem" and check for ".ReceivedTime" property of items. To count, you can loop through items that meet condition and increment counter.
 
Good morning @Chihiro sir, done with the code, thanks for the help.
Please check below code if you get time. :)

Code:
Dim EmailCount As Long
    EmailCount = 0
  
    For Each Item In fld.Items
        MapSht.Range("A1").Value = Item.ReceivedTime
        MapSht.Range("C1").Value = Item.Subject
      
        If MapSht.Range("A5").Value > MapSht.Range("B4").Value Then
            If MapSht.Range("A5").Value <= MapSht.Range("B1").Value Then
                If MapSht.Range("C2").Value = True Then
                    EmailCount = EmailCount + 1
                End If
            End If
        End If
    Next Item
 
Good morning @Chihiro sir, this is not an issue actually. However the code I am using to get count of e-mails takes around 2 minutes to complete.

Is there any way to reduce this time. Could you please help with suggestion if you get time.

Have a nice day ahead. :)
 
Personally, I'd set up filter logic within Outlook to limit the number of mails that you need to loop through.

Say, first logic to put anything within 3 days of today into "Current" folder, and second logic to move anything older than 3 days out of "Current" folder.

Bit busy next couple of weeks, but will see if I can come up with other suggestions and/or code snippets.
 
Hi @Chihiro sir, thanks a lot for the help. Please do not invest your time in writing the code for me, it is not an issue. Meanwhile I will post if found faster alternative.

Have a nice day ahead. :)
 
You can restrict the items returned from the folder:

Code:
Set restrictedItems = fld.Items.Restrict("[ReceivedTime] > '" & Format(Date - 4, "yyyy/mm/dd") & "' AND [MessageClass] = 'IPM.Note'")
for example, then only loop through the restrictedItems collection.
 
Back
Top