Automatically update all inbox counts when opening Outlook

0

This seems like a fairly basic thing to do, but for some reason, it's not.

In Outlook 2010 on Windows XP, I had problems getting inbox counts for all accounts that were not the primary account to update. Despite having each inbox saved as a favorite, only the primary would update when Outlook was opened. The only way to force an update of the unread counts was to click on the favorites, or to expand all the folders. Considering that Outlook insists on expand only the useless "Personal Folders" on startup and always collapses all the IMAP accounts, this gets annoying when you have, say, seven email accounts.

In Outlook 2010, for a while the only solution was to use a VBScript that would iterate through all IMAP folders and expand each solution. It took about 2 minutes to run, so upon opening Outlook, I could not use it for at least 2 minutes. Clearly, such a solution is less than optimal.

I believe in Outlook 2003, I did not have this problem (I had countless others, but not this one). In Outlook 2007, it behaves similarly to Outlook 2010, in that only the folder I expand to upon startup in mail settings is updated. Even though the others have unread emails, it appears as if they don't.

What's the easiest way to remedy this, with or without an official Outlook solution? A VBScript is not off the table, but I'd much rather it take 2 seconds to run, not 2 minutes. One problem with the VBScript I used with Outlook 2010 was that it expanded every single folder - including subfolders. It would've been perfectly fine if it only expanded the root IMAP folders, because only the root IMAP folder of each account needs to be expanded to force the Inbox count to update, but instead it expanded the entire folder hierarchy, which meant instead of expanding 7 IMAP folders, it expanded probably close to 70 or 80 mail folders and subfolders across all 7 accounts.

I managed to find a VBScript that seems to come close, here:

Private Sub Application_Startup()
  ExpandAllIMAPAccounts
End Sub

Private Sub ExpandAllIMAPAccounts()
    On Error GoTo On_Error

    Dim session As Outlook.NameSpace
    Dim report As String
    Dim accounts As Outlook.accounts
    Dim account As Outlook.account

    Set session = Application.session
    Set accounts = session.accounts

    For Each account In accounts
        If account.AccountType = Outlook.OlAccountType.olImap Then
            FocusThisAccountInbox (account.DisplayName & "\Inbox")
        End If
    Next

Exiting:
    Exit Sub
On_Error:
    MsgBox "error=" & Err.Number & " " & Err.Description
    Resume Exiting
End Sub

Private Function FocusThisAccountInbox(ByVal FolderPath As String)
    On Error GoTo On_Error

    Dim oFolder As Outlook.Folder
    Dim FoldersArray As Variant
    Dim SubFolders As Outlook.Folders

    'Convert folderpath to array
    FoldersArray = Split(FolderPath, "\")

    'index 0 = account name
    Set oFolder = Application.session.Folders.Item(FoldersArray(0))

    Set SubFolders = oFolder.Folders

    'index 1 = Inbox folder
    Set oFolder = SubFolders.Item(FoldersArray(1))

    Set Application.ActiveExplorer.CurrentFolder = oFolder
    DoEvents
    Exit Function

Exiting:
    Exit Function
On_Error:
    MsgBox "error=" & Err.Number & " " & Err.Description
    Resume Exiting
End Function

While this does expand IMAP folders quickly, it also breaks Outlook as I get a perpetual "Download Hierarchy" message in the lower-right corner. Outlook can't be used at all unless launched as outlook.exe /safe. When I open the Visual Basic Editor again, it just hangs, and I can't remove the script from ThisOutlookSession.

InterLinked

Posted 2019-12-08T03:26:48.743

Reputation: 1 761

No answers