Some users wish that Outlook can warn you if there are too many unread emails in their inbox, including the subfolders. Though Outlook does not offer such a function, it still can be realized with VBA code. This article will show this code to you.
At times, owing to your busy schedules, you may leave a great number of unread mails in your Inbox. With more and more emails accumulated, dealing with them later will be a quite tedious and troublesome task. In this case, you may hope that Outlook could remind you if the number of unread emails exceeds a specific limit. In the followings, we will share you a means to achieve this function.
Get Warned If There Are Too Many Unread Emails
- To start with, launch your Outlook program as usual.
- Next, in the main Outlook window, press “Alt + F11” key buttons.
- Then, you’ll get into the “Microsoft Visual Basic for Applications” window, in which you need to find and open the “ThisOutlookSession” project.
- Subsequently, you should copy the following VBA code into this project.
Private objInbox As Outlook.Folder Private WithEvents objItems As Outlook.Items Private lUnreadItemCount As Long Private Sub Application_Startup() Set objInbox = Application.Session.GetDefaultFolder(olFolderInbox) Set objItems = objInbox.Items lUnreadItemCount = 0 Call CountUnreadEmails(objInbox, lUnreadItemCount) 'If there are more than 10 unread emails If lUnreadItemCount > 10 Then MsgBox "Too many unread emails in Inbox!" & vbCr & "Please deal with them as soon as possible!", vbExclamation + vbOKOnly, "Check Unread Emails" End If End Sub Private Sub objItems_ItemAdd(ByVal Item As Object) Call CountUnreadEmails(objInbox, lUnreadItemCount) lUnreadItemCount = 0 If lUnreadItemCount > 10 Then MsgBox "Too many unread emails!" & vbCr & "Please deal with them as soon as possible!", vbExclamation + vbOKOnly, "Check Unread Emails" End If End Sub Private Sub CountUnreadEmails(ByVal objFolder As Outlook.Folder, ByRef lCount As Long) Dim objUnreadItems As Outlook.Items Dim objSubfolder As Outlook.Folder Set objUnreadItems = objFolder.Items.Restrict("[Unread] = True") lCount = objUnreadItems.count + lCount 'Process all subfolders under Inbox recursively If objFolder.Folders.count > 0 Then For Each objSubfolder In objFolder.Folders Call CountUnreadEmails(objSubfolder, lCount) Next End If End Sub
- After that, you should sign this code.
- Later, exit the current window and change your Outlook macro settings to enable digitally signed macros.
- Finally, you can restart your Outlook to activate this new macro.
- From now on, every time when you start Outlook and new email arrives in your mailbox, Outlook will auto check the number of unread emails in Inbox and its subfolders.
- If the number exceeds your predefined limit, Outlook will warn you, like the following screenshot:
Retrieve Outlook Data after Abrupt Crashes
Outlook cannot get rid of errors thoroughly. And mounting errors may lead to crashes without any prompts. Serious crashes can damage your Outlook data file in a jiffy. Therefore, it is necessary for you to make sufficient precautions, such as making regular data backups and getting hold of a potent external recovery tool, like DataNumen Outlook Repair. It can assist you to repair PST file with ease.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including mdf fix and outlook repair software products. For more information visit www.datanumen.com