How to Auto Expand All Folders via VBA when Starting Your Outlook

Multiple users hope that all the folders can be automatically expanded when they launch their Outlook. In reality, Outlook doesn’t natively support it. Thus, to realize it, you have to use VBA code. This post will give you a quick guide.

You may have created a lot of subfolders under the default folders in Outlook. In face of so many folders, so as to quickly access them at any time, you may wish to keep all the folders expanded all the time. The first step must be to make Outlook to auto expand the folders on startup. Obviously, there isn’t such a native function in Outlook. Thus, you have to make use of macros. Thereinafter, we will teach you to achieve it with VBA. As for how to apply VBA, you can refer to another article – “How to Run VBA Code in Your Outlook“.

Auto Expand All Folders when Starting Outlook

  1. To begin with, press “Alt + F11” in your Outlook to access VBA editor.
  2. Then, in the new window, put the code into the “ThisOutlookSession” project.
'Auto expand all folders on startup
Private Sub Application_Startup()
    Call ExpandAllFolders
End Sub

Private Sub ExpandAllFolders()
    Dim objCurrentFolder As Outlook.Folder
    Dim objStore As Outlook.Store
    Dim objFileFolders As Outlook.Folders
    Dim objFolder As Outlook.Folder
   
    Set objCurrentFolder = Application.ActiveExplorer.CurrentFolder
 
    'Process all email accounts in your Outlook
    For Each objStore In Outlook.Application.Session.Stores
        Set objFileFolders = objStore.GetRootFolder.Folders
 
        For Each objFolder In objFileFolders
            Call LoopFolders(objFolder)
        Next
 
        DoEvents
        Set Application.ActiveExplorer.CurrentFolder = objCurrentFolder
    Next
End Sub

Sub LoopFolders(ByVal objCurFolder As Outlook.Folder)
    Dim objSubfolder As Outlook.Folder
 
    Set Application.ActiveExplorer.CurrentFolder = objCurFolder
    DoEvents
 
    'Process all subfolders recursively
    If objCurFolder.Folders.Count > 0 Then
       For Each objSubfolder In objCurFolder.Folders
           Call LoopFolders(objSubfolder)
       Next
    End If
End Sub

VBA Code - Auto Expand All Folders when Starting Outlook

  1. After that, close the VBA editor.
  2. Subsequently, exit the Outlook application properly.
  3. Later, start your Outlook. At this point, the macro will run automatically.
  4. After Outlook starts up, you can see that all the folders have been expanded, as shown in the figure below.All Folders Are Expanded

Keep All Malicious Macros at Bay

Have you ever received the emails which are attached with suspicious files or are embedded with unknown links? Usually, when confronting such emails, you have to raise your vigilance. You should never readily trust in them in that they might carry viruses. Once you download the attachments or open the links, not only the Outlook but also the computer might be attacked. At that time, you have to repair Outlook file. It could be quite knotty unless you have an updated Outlook backup or make use of a powerful recovery tool, such as DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including SQL Server corruption and outlook repair software products. For more information visit www.datanumen.com