Counting Number of emails received in outlook per month in a year

vij

Board Regular
Joined
Feb 13, 2011
Messages
215
Hi,
At the outset I had posted this under Excel Questions also today which may not be the appropriate forum I feel hence a repeat post here.

I have over 75000 emails that I received/replied from Jan 2015 to Dec 2015.
I want to count the total number of emails which I received/sent per month from Jan to Dec 2015.
Is this possible?

I am using MS Outlook 2013.

Thanks,
Vij:confused:
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I have moderated the other two posts and removed them from the system
 
Upvote 0
Hi Vij
assuming you are looking only in a default inbox and sent mail folders, this macro should work
it could be slow if you have a lot of emails
it will display a text box with the number of emails received and sent each month, and also copy the text to the clipboard

Code:
Sub CountEmails()
    Dim MyNameSpace As Outlook.NameSpace
    Dim InFolder As Outlook.folder
    Dim SentFolder As Outlook.folder
    Dim MyText As DataObject
    Dim x As Long, n As Long, InArray(11) As Variant, SentArray(11) As Variant, MonthArray As Variant, txt As String
    
    For x = 0 To 11
        SentArray(x) = 0
        InArray(x) = 0
    Next x
    
    MonthArray = Split("Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec", ",")
    
    Set MyNameSpace = Application.GetNamespace("MAPI")
    Set InFolder = MyNameSpace.GetDefaultFolder(olFolderInbox)
    Set SentFolder = MyNameSpace.GetDefaultFolder(olFolderSentMail)
    
    For n = 1 To SentFolder.items.Count
        On Error Resume Next
        x = Month(SentFolder.items(n).SentOn) - 1
        SentArray(x) = SentArray(x) + 1
    Next n
    
    For n = 1 To InFolder.items.Count
        On Error Resume Next
        x = Month(InFolder.items(n).SentOn) - 1
        InArray(x) = InArray(x) + 1
    Next n
    
    txt = ""
    For n = 0 To 11
    txt = txt & MonthArray(n) & "  - emails sent: " & SentArray(n) & " ; emails received: " & InArray(n) & Chr(13)
    Next n
    MsgBox txt


Set MyText = New DataObject
MyText.SetText txt
MyText.PutInClipboard

End Sub
 
Upvote 0
Hi NickyCC,
Thanks for such a prompt response.
Am I pasting the code in the correct place.
This is the error I am getting.
 
Last edited by a moderator:
Upvote 0
Hi NickyCC,

I was trying to attach an image but goofed up. Apologies for the same.
Thanks for such a prompt response.
Where and how do I paste the code.

Vij
 
Upvote 0
Hi Vij
not sure what's happening there, but I think you must have copied it in the wrong place. To run a macro in Outlook you must have macros enabled in your Outlook settings and have the developer tab visible. Then copy the code into Visual Basic (on the developer tab, select Visual Basic and insert a new module if necessary, then run the macro.
 
Upvote 0
Still getting an error as under
Sub CountEmails()
Dim MyNameSpace As Outlook.NameSpace
Dim InFolder As Outlook.Folder
Dim SentFolder As Outlook.Folder
Dim MyText As DataObject
Dim x As Long, n As Long, InArray(11) As Variant, SentArray(11) As Variant, MonthArray As Variant, txt As String


Compile error!!!
User type not defined.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,909
Messages
6,122,189
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top