How to count the number of sent emails per month in Outlook?
Sometimes, you may want to know how many emails that you have sent per month. This tutorial will introduce a VBA code for you to count the number of sent emails per month in Outlook.
Count the number of sent emails per month in Outlook with VBA code
Please apply the below VBA code to get the number of sent emails each month as shown below:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Count the number of sent emails per month:
Dim GDictionary As Object
Sub CountSentMailsByMonth()
'Updateby Extendoffice
Dim xSentFolder As Outlook.Folder
Dim xExcelApp As Excel.Application
Dim xWb As Excel.Workbook
Dim xWs As Excel.Worksheet
Dim xMonths As Variant
Dim xItemsCount As Variant
Dim xLastRow As Integer
Dim I As Integer
Dim xAccount As Account
On Error Resume Next
Set GDictionary = CreateObject("Scripting.Dictionary")
For Each xAccount In Application.Session.Accounts
If VBA.LCase$(xAccount.SmtpAddress) = VBA.LCase$("") Then 'Specify the Email Account
Set xSentFolder = xAccount.DeliveryStore.GetDefaultFolder(olFolderSentMail)
If xSentFolder.DefaultItemType = olMailItem Then
Call ProcessFolders(xSentFolder)
End If
End If
Next
Set xSentFolder = Nothing
Set xExcelApp = CreateObject("Excel.Application")
xExcelApp.Visible = True
Set xWb = xExcelApp.Workbooks.Add
Set xWs = xWb.Sheets(1)
With xWs
.Cells(1, 1) = "Month"
.Cells(1, 2) = "Count"
.Cells(1, 1).Font.Bold = True
.Cells(1, 2).Font.Bold = True
.Cells(1, 1).HorizontalAlignment = xlCenter
.Cells(1, 2).VerticalAlignment = xlCenter
End With
xMonths = GDictionary.Keys
xItemsCount = GDictionary.Items
For I = LBound(xMonths) To UBound(xMonths)
xLastRow = xWs.Range("A" & xWs.Rows.Count).End(xlUp).Row + 1
With xWs
.Cells(xLastRow, 1) = xMonths(I)
.Cells(xLastRow, 2) = xItemsCount(I)
End With
Next
xWs.Columns("A:B").AutoFit
xExcelApp.Visible = True
Set xExcelApp = Nothing
Set xWb = Nothing
Set xWs = Nothing
End Sub
Sub ProcessFolders(ByVal Fld As Outlook.Folder)
Dim I As Long
Dim xMail As Outlook.MailItem
Dim xMonth As String
Dim xSubFolder As Folder
On Error Resume Next
For I = Fld.Items.Count To 1 Step -1
If Fld.Items(I).Class = olMail Then
Set xMail = Fld.Items(I)
xMonth = Year(xMail.SentOn) & "/" & Month(xMail.SentOn)
If GDictionary.Exists(xMonth) Then
GDictionary(xMonth) = GDictionary(xMonth) + 1
Else
GDictionary.Add xMonth, 1
End If
End If
Next
If Fld.Folders.Count > 0 Then
For Each xSubFolder In Fld.Folders
Call ProcessFolders(xSubFolder)
Next
End If
End Sub
3. Still in the Microsoft Visual Basic for Applications window, click Tools > References, in the References-Project dialog box, check Microsoft Excel 16.0 Object Library option from the Available References list box, see screenshot:
4. Then click OK to close the dialog box, and press F5 key to run this code. Then, an Excel file will open, which displays the counts of sent emails of each month for the specific account, see screenshot:
Best Office Productivity Tools
Kutools for Outlook - Over 100 Powerful Features to Supercharge Your Outlook
π§ Email Automation: Out of Office (Available for POP and IMAP) / Schedule Send Emails / Auto CC/BCC by Rules When Sending Email / Auto Forward (Advanced Rules) / Auto Add Greeting / Automatically Split Multi-Recipient Emails into Individual Messages ...
π¨ Email Management: Easily Recall Emails / Block Scam Emails by Subjects and Others / Delete Duplicate Emails / Advanced Search / Consolidate Folders ...
π Attachments Pro: Batch Save / Batch Detach / Batch Compress / Auto Save / Auto Detach / Auto Compress ...
π Interface Magic: πMore Pretty and Cool Emojis / Boost Your Outlook Productivity with Tabbed Views / Minimize Outlook Instead of Closing ...
π One-click Wonders: Reply All with Incoming Attachments / Anti-Phishing Emails / πShow Sender's Time Zone ...
π©πΌβπ€βπ©π» Contacts & Calendar: Batch Add Contacts From Selected Emails / Split a Contact Group to Individual Groups / Remove Birthday Reminders ...
Over 100 Features Await Your Exploration! Click Here to Discover More.