Outlook: How to Count Emails Received in Date Range


Often you may want to count the number of emails received during a specific date range in Outlook.

The best way to do so is by writing some code in VBA.

The following step-by-step example shows exactly how to do so.

Note: You do not need any prior knowledge of VBA to use the code in this example. You will simply copy and paste the code provided.

Example: How to Count Emails by Date Range in Outlook

First, open Outlook.

Then, type Alt + F11. This will bring up the VBA Editor.

Next, click the Insert tab, then click Module:

Next, paste the following code into the Module window:

Sub CountEmails()
    Dim objNamespace As Outlook.NameSpace
    Dim objFolder As Outlook.Folder
    Dim objItems As Outlook.Items
    Dim objMail As Outlook.MailItem
    Dim startDate As Date
    Dim endDate As Date
    Dim emailCount As Long
    Dim item As Object
    
    emailCount = 0
    
    On Error Resume Next
    startDate = CDate(InputBox("Enter the starting date (MM/DD/YYYY):", "Start Date"))
    endDate = CDate(InputBox("Enter the ending date (MM/DD/YYYY):", "End Date"))
    On Error GoTo 0
    
    If startDate = 0 Or endDate = 0 Then
        MsgBox "Invalid date(s) provided. Exiting.", vbExclamation
        Exit Sub
    End If
    
    If endDate < startDate Then MsgBox "The ending date must be after the starting date. Exiting.", vbExclamation Exit Sub End If Set objNamespace = Application.GetNamespace("MAPI") Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox) Set objItems = objFolder.Items For Each item In objItems If TypeOf item Is Outlook.MailItem Then Set objMail = item If objMail.ReceivedTime >= startDate And objMail.ReceivedTime <= endDate Then
                emailCount = emailCount + 1
            End If
        End If
    Next item
    
    MsgBox "You have received " & emailCount & " email(s) from " & _
           Format(startDate, "MM/DD/YYYY") & " to " & Format(endDate, "MM/DD/YYYY") & ".", _
           vbInformation, "Email Count"
End Sub

Next, close out of the VBA Editor.

Once you’re back in Outlook, type Alt + F8. Then click CountEmails. Then click Run.

Once you click Run, a message box will appear that asks you to specify the starting date to use:

Once you click OK, another message box will appear that asks you to specify an ending date to use:

Once you click OK, a final message box will appear that tells you how many emails you received during the date range that you specified:

Outlook count emails by date range

In this example we can see that we received 4 total emails between 5/20/2024 and 9/28/2024.

Feel free to type Alt+F8 to use this VBA code whenever you would like to count the number of emails that you received during a specific date range.

Related Tutorials

The following tutorials explain how to perform other common tasks in Outlook:

Outlook: How to Search Emails by Date Range
Outlook: How to Count Emails from Specific Sender
Outlook: How to Count Selected Emails

Leave a Reply