How to Quickly Jump to the Folder Containing the Most Unread Emails in Outlook

If there are a lot of mail folders containing unread emails, you may want to quickly access the folder that has most unread emails. Now, this article will teach you to realize it in quick time.

Perhaps you have created multiple mail subfolders under Inbox. And there are many rules which will auto move and scatter the new incoming emails to inbox and all its subfolders. In this situation, at times, no matter Inbox or the subfolders, they are all likely to contain unread emails. Thus, in face of so many folders which contain unread emails, you may wish to firstly open the folder having most unread mails. Thereinafter, we will show you a quick and effective solution.

Jump to the Folder Containing the Most Unread Emails

  1. At the outset, go to VBA editor in Outlook with accordance to “How to Run VBA Code in Your Outlook“.
  2. Then, enable reference to “Microsoft Scripting Run Time” by referring to “How to Add an Object Library Reference in VBA“.
  3. Next, put the following code into a module in VBA editor.
Dim objDictionary As New Scripting.Dictionary

Sub JumpToFolder_WithMostUnreadEmails()
    Dim objOutlookFile, objFolder As Outlook.Folder
    Dim varFolder As Variant
    Dim objTargetFolder As Outlook.Folder
 
    'Get the counts of unread emails in all folders via Dictionary
    Set objDictionary = CreateObject("Scripting.Dictionary")
    Set objOutlookFile = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Parent
 
    For Each objFolder In objOutlookFile.Folders
        If objFolder.DefaultItemType = olMailItem Then
           Call ProcessFolders(objFolder)
        End If
    Next
 
    'Get & access the folder having most unread emails
    Set objDictionary = SortDictionary(objDictionary)
    varFolder = objDictionary.Keys(0)
 
    Set objTargetFolder = GetFolder(varFolder)
    Set Application.ActiveExplorer.CurrentFolder = objTargetFolder
End Sub

Sub ProcessFolders(ByVal objFolder As Outlook.Folder)
    Dim objUnreadItems As Outlook.Items
    Dim objSubFolder As Outlook.Folder
   
    Set objUnreadItems = objFolder.Items.Restrict("[Unread]=true")
    objDictionary.Add objFolder.FolderPath, objUnreadItems.Count
    Set objUnreadItems = Nothing
 
    If objFolder.Folders.Count > 0 Then
       For Each objSubFolder In objFolder.Folders
           Call ProcessFolders(objSubFolder)
       Next
    End If
End Sub

'Sort the folder by counts
Function SortDictionary(objCurDictionary As Object) As Object
    Dim objArrayList As Object
    Dim objTempDictionary As New Scripting.Dictionary
    Dim varKey As Variant
    Dim varValue As Variant
    Dim objCollection As Collection
    Dim varItem As Variant
 
    Set objArrayList = CreateObject("System.Collections.ArrayList")
    Set objTempDictionary = CreateObject("Scripting.Dictionary")
 
    For Each varKey In objCurDictionary.Keys
        varValue = objCurDictionary(varKey)
 
        If objTempDictionary.Exists(varValue) = False Then
           Set objCollection = New Collection
           objTempDictionary.Add varValue, objCollection
           objArrayList.Add varValue
        End If
 
       objTempDictionary(varValue).Add varKey
    Next
 
    objArrayList.Sort
    objArrayList.Reverse
    objCurDictionary.RemoveAll
    
    For Each varValue In objArrayList
        Set objCollection = objTempDictionary(varValue)
        For Each varItem In objCollection
            objCurDictionary.Add varItem, varValue
        Next
    Next
 
    Set SortDictionary = objCurDictionary
End Function

'Get the folder by folder path
Function GetFolder(ByVal strPath As String) As Outlook.Folder
    Dim objFolder As Outlook.Folder
    Dim varFoldersArray As Variant
    Dim i As Integer
    Dim objSubFolders As Outlook.Folders

    If Left(strPath, 2) = "\" Then
       strPath = Right(strPath, Len(strPath) - 2)
    End If
 
    varFoldersArray = Split(strPath, "\")
    Set objFolder = Application.Session.Folders.Item(varFoldersArray(0))
    If Not objFolder Is Nothing Then
       For i = 1 To UBound(varFoldersArray, 1)
           Set objSubFolders = objFolder.Folders
           Set objFolder = objSubFolders.Item(varFoldersArray(i))
           If objFolder Is Nothing Then
              Set GetFolder = Nothing
           End If
        Next
    End If
 
    Set GetFolder = objFolder
End Function

VBA Code - Jump to the Folder Containing the Most Unread Emails

  1. Next, add this macro to Quick Access Toolbar.
  2. Now, return to the mail navigation pane.
  3. Later, click the macro button in Quick Access Toolbar.
  4. At once, the folder containing the most unread emails will be opened, as shown in the following figure.Jump to the Folder Containing the Most Unread Emails

Back up Your Outlook Files Periodically

To avoid miserable Outlook data loss, you are better off making regular backups for your Outlook files. By this means, even though Outlook file gets corrupt, you can easily recover Outlook from backup. If without backups, you’ll need to repair the damaged Outlook file.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including mdf repair and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.