Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to automatically expand all folders when starting Outlook?

Generally speaking, if you expand or collapse a folder on the Navigation Pane and then close the Outlook, the folder will remain expanding or collapsing when restarting Outlook. But now, is there a way to expand all folders automatically when starting Outlook? This article will introduce a VBA to complete the task.

Automatically expand all folders when starting Outlook with VBA

Kutools for Outlook: 100+ New Advanced Tools for Outlook.
Office Tab: Enable Tabbed Editing and Browsing in Office, Just Like Chrome, Firefox, IE 8/9/10.
Classic Menu: Bring Old Menus and Toolbars Back to Office 2007, 2010, 2013, 2016 and 2019.

arrow blue right bubbleAutomatically expand all folders when starting Outlook with VBA

This method will introduce a VBA to automatically expand all folders on the Navigation Pane when you start Outlook. Please apply this VBA as follows:

1. Press Alt + F11 keys simultaneously to open the Microsoft Visual Basic for Applications window.

2. Expand the Project 1 and Microsoft Outlook Objects in the Project pane, double click to open the ThisOutlookSession window, and then paste below VBA code into it.

VBA: Automatically expand all folders in Outlook

Private Sub Application_Startup()
ExpandAllFolders
End Sub

Private Sub ExpandAllFolders()
On Error Resume Next
Dim Ns As Outlook.NameSpace
Dim Folders As Outlook.Folders
Dim CurrF As Outlook.MAPIFolder
Dim F As Outlook.MAPIFolder
Dim ExpandDefaultStoreOnly As Boolean

  ExpandDefaultStoreOnly = False

  Set Ns = Application.GetNamespace("Mapi")
Set CurrF = Application.ActiveExplorer.CurrentFolder

  If ExpandDefaultStoreOnly = True Then
Set F = Ns.GetDefaultFolder(olFolderInbox)
Set F = F.Parent
Set Folders = F.Folders
LoopFolders Folders, True

  Else
LoopFolders Ns.Folders, True
End If

  DoEvents
Set Application.ActiveExplorer.CurrentFolder = CurrF
End Sub

Private Sub LoopFolders(Folders As Outlook.Folders, _
ByVal bRecursive As Boolean _
)
Dim F As Outlook.MAPIFolder

  For Each F In Folders
Set Application.ActiveExplorer.CurrentFolder = F
DoEvents

    If bRecursive Then
If F.Folders.Count Then
LoopFolders F.Folders, bRecursive
End If
End If
Next
End Sub

3. Save the code and close the Microsoft Visual Basic for Applications window.

From now on, when restarting Outlook, all folders will be automatically expanded in Outlook.Note: This VBA cannot open the collapsed search folders when restarting Outlook.


arrow blue right bubbleRelated Articles



Kutools for Outlook

More than 100 Advanced Functions for Outlook 2010, 2013, 2016, 2019 and 365

screen shot kutools for outlook tiny for banner 201812

More Features  |  Free Download  |  Only $39.00 for hundreds of functions

Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Selvi · 7 months ago
    Thank you so much.. It solved my problem. :)