How to automatically expand all folders when starting Outlook?
Typically, when you expand or collapse a folder in Outlook's Navigation Pane and subsequently close the program, the folder retains its expanded or collapsed state upon reopening Outlook. However, what if you want all folders to be automatically expanded every time you start Outlook? This article provides a VBA solution to achieve just that.
Automatically expand all folders when starting Outlook using VBA
- Enhance your email productivity with AI technology, enabling you to quickly reply to emails, draft new ones, translate messages, and more efficiently.
- Automate emailing with Auto CC/BCC, Auto Forward by rules; send Auto Reply (Out of Office) without requiring an exchange server...
- Get reminders like BCC Warning when replying to all while you're in the BCC list, and Remind When Missing Attachments for forgotten attachments...
- Improve email efficiency with Reply (All) With Attachments, Auto Add Greeting or Date & Time into Signature or Subject, Reply Multiple Emails...
- Streamline emailing with Recall Emails, Attachment Tools (Compress All, Auto Save All...), Remove Duplicates, and Quick Report...
Automatically expand all folders when starting Outlook using VBA
This guide will demonstrate how to use a VBA script to automatically expand all folders in the Navigation Pane each time you launch Outlook. Follow these steps to implement the VBA script:
- Press Alt + F11 keys simultaneously to open the Microsoft Visual Basic for Applications window.
- Expand the Project 1 and Microsoft Outlook Objects in the Project pane, double click to open the ThisOutlookSession window, and then paste the below VBA code into it.
VBA: Automatically expand all folders in Outlook
Public WithEvents GEx As Explorer Public GFlag As Boolean Private Sub Application_Startup() 'Update by ExtendOffice 2023/12/08 Set GEx = Application.ActiveExplorer GFlag = False End Sub Private Sub GEx_SelectionChange() If GFlag = False Then ExpandAllFolders End If GFlag = True 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
- 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.
Notes:
- This VBA cannot open the collapsed search folders when restarting Outlook.
- To ensure the VBA script functions correctly, it's essential to adjust your macro settings in Outlook. Please go to File > Options > Trust Center > Trust Center Settings > Macro Settings, and select the Enable all macros option. This setting allows the VBA script to run without any restrictions.
Related Articles
Best Office Productivity Tools
Breaking News: Kutools for Outlook Launches Free Version!
Experience the all-new Kutools for Outlook FREE version with 70+ incredible features, yours to use FOREVER! Click to download now!
📧 Email Automation: Auto Reply (Available for POP and IMAP) / Schedule Send Emails / Auto CC/BCC by Rules When Sending Email / Auto Forward (Advanced Rules) / Auto Add Greeting / Automatically Split Multi-Recipient Emails into Individual Messages ...
📨 Email Management: Recall Emails / Block Scam Emails by Subjects and Others / Delete Duplicate Emails / Advanced Search / Consolidate Folders ...
📁 Attachments Pro: Batch Save / Batch Detach / Batch Compress / Auto Save / Auto Detach / Auto Compress ...
🌟 Interface Magic: 😊More Pretty and Cool Emojis / Remind you when important emails come / Minimize Outlook Instead of Closing ...
👍 One-click Wonders: Reply All with Incoming Attachments / Anti-Phishing Emails / 🕘Show Sender's Time Zone ...
👩🏼🤝👩🏻 Contacts & Calendar: Batch Add Contacts From Selected Emails / Split a Contact Group to Individual Groups / Remove Birthday Reminders ...