If you would like to count the number of incoming emails on a specific date, or in a specific month or year, you can use the quick means introduced in this article. It will teach you how to use VBA to get it in a flash.
When it comes to counting how many emails received in specific date or periods, many are accustomed to using Outlook search folder, which permits us to gather all the emails incoming in the specific date or date range in a single search folder. Then we can use the “show total number of items” feature for mail folder to get it. However, without any doubts, this method is quite troublesome. Thus, here we’ll teach you another trick, which can make use of Outlook VBA to help you get the total count. Now read on to learn the detailed steps and codes.
Count Incoming Emails by Date
- To start with, launch your Outlook program properly.
- Then you can switch to “Developer” tab and click the “Visual Basic” button.
- Next in the popup Outlook VBA editor window, you can open a new module by “Insert” > “Module”.
- Subsequently, copy the following VBA codes into the new module.
'The following codes are working to count by day Sub CountReceivedEmailsbyDay() Dim objItems As Outlook.Items Dim objItem As Object Dim objMail As Outlook.MailItem Dim strDay As String Dim dReceivedTime As Date Dim strReceivedDate As String Dim i, n As Long Dim strMsg As String Dim nPrompt As Integer Set objItems = Outlook.Application.ActiveExplorer.CurrentFolder.Items objItems.SetColumns ("ReceivedTime") strDay = InputBox("Enter the specific day.(Format: yyyy-mm-dd)", "Specify Date") If strDay <> "" Then n = 0 For i = 1 To objItems.Count If objItems.Item(i).Class = olMail Then Set objMail = objItems.Item(i) dReceivedTime = objMail.ReceivedTime strReceivedDate = Year(dReceivedTime) & "-" & Month(dReceivedTime) & "-" & Day(dReceivedTime) If strReceivedDate = strDay Then n = n + 1 End If End If Next i strMsg = "You have received " & n & " emails on " & strDay & "." nPrompt = MsgBox(strMsg, vbExclamation, "Count Received Emails") Else nPrompt = MsgBox("Please input the specific day!", vbExclamation) End If End Sub
Note: This above code is working to count the incoming emails by date.
- After that, you can add the new macro to Quick Access Toolbar as usual.
- Finally, you can have a try.
- Firstly, select the Inbox folder.
- Then click on the button in Quick Access Toolbar.
- Next you need to input a specific date in the format of “yyyy-mm-dd”.
- Lastly, you will receive a prompt of the total count, like the image below:
Count Incoming Emails by Month or Year
As the above code is specified for counting by day, if you want to count by month or year, you need to make some changes on the codes.
- Firstly, change all “strDay” to strMonth or strYear.
- Secondly, replace the line “strDay = InputBox(“Enter the specific day.(Format: yyyy-mm-dd)”, “Specify Date”)” with:
- strMonth = InputBox(“Enter the specific month.(Format: yyyy-mm)”, “Specify Month”)
- strYear = InputBox(“Enter the specific year.(Format: yyyy)”, “Specify Year”)
- Thirdly, change the line “strReceivedDate = Year(dReceivedTime) & “-” & Month(dReceivedTime) & “-” & Day(dReceivedTime)” to:
- strReceivedDate = Year(dReceivedTime) & “-” & Month(dReceivedTime) [for month]
- strReceivedDate = Year(dReceivedTime) [for year].
What Will Occur after Outlook Crashes
Many users have ever suffered Outlook crash. At best, after restarting Outlook, all things will get restored, namely nothing will happen. However, at worst, you may encounter severe PST corruption. At that point, assuming you don’t have current data backups, your last resort is, unquestionably, a remarkable repair tool, such as DataNumen Outlook Repair.
Author Introduction:
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including sql recovery and outlook repair software products. For more information visit www.datanumen.com