How to Get Warned If There Are Too Many Unread Emails in Your Outlook Inbox

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 in Your Outlook Inbox

Get Warned If There Are Too Many Unread Emails

  1. To start with, launch your Outlook program as usual.
  2. Next, in the main Outlook window, press “Alt + F11” key buttons.
  3. Then, you’ll get into the “Microsoft Visual Basic for Applications” window, in which you need to find and open the “ThisOutlookSession” project.
  4. 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

VBA Code - Get Warned If There Are Too Many Unread Emails

  1. After that, you should sign this code.
  2. Later, exit the current window and change your Outlook macro settings to enable digitally signed macros.
  3. Finally, you can restart your Outlook to activate this new macro.
  4. 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.
  5. If the number exceeds your predefined limit, Outlook will warn you, like the following screenshot:Warning

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.

Author Introduction:

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

One response to “How to Get Warned If There Are Too Many Unread Emails in Your Outlook Inbox”

  1. I know this post is a bit old, but on the sub module objItems_ItemAdd you are resetting the count to 0 after you do the count, so the If statement never returns true and never runs..

Leave a Reply

Your email address will not be published. Required fields are marked *