• 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.

Classic : Count Emails in Excel

ianb

Member
THANK YOU TO JB01 AND HUI FOR THE HELP RETURNING THE FAVOR FOR EXCEL PEOPLE.

[pre]
Code:
'Please note A2 will contain the date
' enter this into A2
' =TODAY()
' ?????? : enter info if required.

Sub CountEmail()

Dim objOutlook As Object, objnSpace As Object, objFolder As Object
Dim EmailCount As Integer
Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")

On Error Resume Next
Set objFolder = objnSpace.Folders("Mailbox - ???????").Folders("Inbox").Folders("????")
If Err.Number <> 0 Then
Err.Clear
MsgBox "No such folder."
Exit Sub
End If

Dim iCount As Integer, DateCount As Integer
Dim myDate As Date
EmailCount = objFolder.Items.Count
DateCount = 0
myDate = Sheets("????????").Range("A2").Value
For iCount = 1 To EmailCount
With objFolder.Items(iCount)
If DateSerial(Year(.ReceivedTime), Month(.ReceivedTime), Day(.ReceivedTime)) = myDate Then DateCount = DateCount + 1
End With
Next iCount

Set objFolder = Nothing
Set objnSpace = Nothing
Set objOutlook = Nothing

MsgBox "Number of Emails Counted for Today : " & DateCount, , "Title Me please"

Sheets("????").Select
Range("B2").Value = DateCount

'End of Email count code

End Sub
[/pre]
 
Back
Top