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
- Auto CC/BCC by rules when sending email; Auto Forward Multiple Emails by rules; Auto Reply without exchange server, and more automatic features...
- BCC Warning - show message when you try to reply all if your mail address is in the BCC list; Remind When Missing Attachments, and more remind features...
- Reply (All) With All Attachments in the mail conversation; Reply Many Emails at once; Auto Add Greeting when reply; Auto Add Date&Time into subject...
- Attachment Tools: Auto Detach, Compress All, Rename All, Auto Save All... Quick Report, Count Selected Mails, Remove Duplicate Mails and Contacts...
- More than 100 advanced features will solve most of your problems in Outlook 2021 - 2010 or Office 365. Full features 60-day free trial.
Automatically 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()
'Update by ExtendOffice 2022/08/03
ExpandAllFolders
End Sub
Public Sub ExpandAllFolders()
Dim xNameSpace As Outlook.NameSpace
Dim xFlds As Outlook.Folders
Dim xCurrFld As Outlook.MAPIFolder
Dim xFld As Outlook.MAPIFolder
Dim xExpandDefaultStoreOnly As Boolean
Dim xModule As NavigationModule
On Error Resume Next
xExpandDefaultStoreOnly = False
Set xNameSpace = Application.Session
Set xModule = Application.ActiveExplorer.NavigationPane.CurrentModule
Set xCurrFld = Application.ActiveExplorer.CurrentFolder
If xExpandDefaultStoreOnly = True Then
Set xFld = xNameSpace.GetDefaultFolder(olFolderInbox)
Set xFld = xFld.Parent
Set xFlds = xFld.Folders
LoopFolders xFlds, True
Else
LoopFolders xNameSpace.Folders, True
LoopFolders xNameSpace.Folders, False
End If
DoEvents
Set Application.ActiveExplorer.NavigationPane.CurrentModule = xModule
Set Application.ActiveExplorer.CurrentFolder = xCurrFld
Set xNameSpace = Nothing
Set xModule = Nothing
Set xCurrFld = Nothing
End Sub
Private Sub LoopFolders(Flds As Outlook.Folders, ByVal All As Boolean)
Dim xFld As Outlook.MAPIFolder
On Error Resume Next
For Each xFld In Flds
Select Case All
Case True
If xFld.DefaultItemType = olMailItem Then
Set Application.ActiveExplorer.CurrentFolder = xFld
DoEvents
If xFld.Folders.Count > 0 Then
LoopFolders xFld.Folders, All
End If
End If
Case False
Set Application.ActiveExplorer.CurrentFolder = xFld
DoEvents
If xFld.Folders.Count > 0 Then
LoopFolders xFld.Folders, All
End If
End Select
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.
Related Articles
Best Office Productivity Tools
Kutools for Outlook - Over 100 Powerful Features to Supercharge Your Outlook
✔ Email Automation: Auto Reply (Out of Office) / Schedule Send emails / Auto CC/BCC / Advanced Auto Forward / Auto Add Greating ...
✉ Email Management: Easily Recall Emails / Block Scam Emails / Delete Duplicate Emails / 🔎Advanced Search / Consolidate Folders ...
📁 Attachments Pro: Batch Save / Batch Detach / Batch Compress / Auto Save / Auto Detach / Auto Compress ...
🌟 Interface & Interaction Magic: 😊More Pretty and Cool Emojis / Brings Browser Tabs Right Into Your Outlook / Minimize Outlook Instead of Closing ...
👍 One-click Wonders: Reply All with Incoming Attachments / Anti-Phishing Emails / 🕘Show Sender's Time Zone / Send to Recipients Separately ...
👩🏼🤝👩🏻 Contacts & Calendar: Batch Add Contacts From Selected Emails / Split a Contact Group to Individual Groups / Remove Birthday Reminders ...
Over 100 Features Await Your Exploration! Click Here to Discover More.




