Ensuring that the current folder is shown in the folder pane in Outlook using VBA

Ariel Rogson 41 Reputation points
2025-12-10T23:15:45.66+00:00

I have some a VBA macro for Outlook that can take a string, locate the folder with that string as its name, and open the folder in the ActiveExplorer. All of this works fine. But while the folder pane in Outlook is updated so that the found folder (now the current folder) can be located (it might be nested several levels deep that weren't opened before), the opening of the nesting results in the current folder potentially being far down the list of folders in the folder pane, rather than visible on the screen.

I note that when I click on a favorite folder, the folder pane is not updated. But if I move backward and/or forward through folders that were opened, the folder pane is sometimes updated. So, it appears that Outlook doesn't always update the folder pane, even when using default functionality.

Is there a way in Outlook VBA to ensure that the current folder is visible in the folder pane?

Outlook | Windows | Classic Outlook for Windows | For home
0 comments No comments
{count} votes

Answer accepted by question author
  1. Kimberly Olaño 19,780 Reputation points Independent Advisor
    2025-12-11T22:45:00.2766667+00:00

    Actually, Outlook VBA cannot scroll the Mail Folder Pane into view without switching its pane type. But there is one workaround that keeps Favorites visible, keeps you in the Mail module, and does not switch to the Folder List / Folder Pane view.

    It relies on triggering a Mail Module refresh via an internal command in the Ribbon/CommandBars.

    When Outlook is already in the Mail module and receives a “refresh mail” command, it re-renders the Folder Pane, and the rendering routine always scrolls to the active folder.

    Here's the code:

    Sub RevealCurrentFolderWithoutChangingPaneType()

    Dim exp As Explorer

    Dim cb As CommandBar

    Dim cbc As CommandBarControl

    Set exp = Application.ActiveExplorer

    'Force Outlook to refresh only the Mail Folder Pane

    On Error Resume Next

    Set cb = exp.CommandBars("Standard")

    If Not cb Is Nothing Then

    Set cbc = cb.FindControl(Id:=2521) ' "Refresh Mail" command

    If Not cbc Is Nothing Then cbc.Execute

    End If

    'Reapply current folder (triggers navigation refresh without switching views)

    Set exp.CurrentFolder = exp.CurrentFolder

    End Sub

    What this does

    • Calls Outlook’s internal “Refresh Mail View” command (ID 2521).
    • Outlook re-draws the Mail Folder Pane without switching to Folder List view.
    • During this redraw, Outlook automatically scrolls to the active folder — same behavior as when you manually click a folder in the Mail tree.
    • Favorites remain unchanged and visible.

    Result

    You remain in Mail view, your Favorites remain untouched and the folder tree scrolls to the current folder.


1 additional answer

Sort by: Most helpful
  1. Kimberly Olaño 19,780 Reputation points Independent Advisor
    2025-12-11T02:05:14.17+00:00

    Thanks for the details, Ariel! Try to Use Outlook’s Built-In Navigation Commands

    Outlook has hidden built-in commands that simulate user navigation in the Folder Pane, such as:

    • Go to Folder Pane
    • Move to Next Folder
    • Move to Previous Folder

    These can be triggered programmatically and force Outlook to refresh and scroll the Folder Pane to the current folder.

    Working VBA Code

    This method sends the keyboard focus to the Folder Pane and forces Outlook to recalculate which folder should be visible.

    Sub RevealCurrentFolderUsingNavigationCommands()

    Dim cb As CommandBar

    Dim cbc As CommandBarControl

    'Force focus to Folder Pane

    On Error Resume Next

    Set cb = Application.ActiveExplorer.CommandBars("Navigation Pane")

    If Not cb Is Nothing Then

    Set cbc = cb.FindControl(Id:=30521) ' "Folder Pane" focus command

    If Not cbc Is Nothing Then cbc.Execute

    End If

    'Now re-apply current folder to trigger UI refresh

    Set Application.ActiveExplorer.CurrentFolder = Application.ActiveExplorer.CurrentFolder

    End Sub

    This moves focus into the Folder Pane (like pressing Ctrl+6 or clicking the pane). Forces Outlook to re-evaluate and scroll to the selected folder. No folder switching, no item selection, no API hacks.

    See if this helps. If you need further assistance just let me know.

    Best regards,

    Kimberly


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.