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 get list of folders in Outlook?

Sometimes the tree structure of all mail folders (include the created personal folders) in the Navigation Pane can do some help for Outlook users during their work. For quickly list the whole tree structure folders, the VBA code can help you. In this tutorial, you can learn how to get list of folders easily with VBA code.

Get list of folders in Outlook with VBA code

Office Tab - Enable Tabbed Editing and Browsing in Office, and Make Work Much Easier...
Kutools for Outlook - Brings 100 Powerful Advanced Features to Microsoft Outlook
  • 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 2010-2019 and 365. Full features 60-day free trial.

arrow blue right bubbleGet list of folders in Outlook with VBA code

For getting list of folders in Outlook with VBA code, please do as follows.

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

2. Then double click the Project1 > Microsoft Outlook Object > ThisOutlookSession to open the Project1 – ThisOutlookSession window. See screenshot:

3. Then copy and paste the below VBA code into the Project1 – ThisOutlookSession window.

VBA: get list of folders in Outlook

Option Explicit
Sub GetFoldersList()
    On Error GoTo On_Error
    
    Dim Report As String
    Dim Folder As Outlook.Folder
       
    For Each Folder In Application.Session.Folders
        Report = Report & "---------------------------------------------------------------------------" & vbCrLf
        Call RecurseFolders(Folder, "", Report)
    Next
    Call CreateReportEmail("Outlook Folders List", Report)
    
Exiting:
    Exit Sub
On_Error:
    MsgBox "error=" & Err.Number & " " & Err.Description
End Sub
Sub RecurseFolders(CurrentFolder As Outlook.Folder, TabChars, ByRef Report As String)
    Dim SubFolder As Outlook.Folder
    Dim FolderName, StoreName As String
    
    FolderName = CurrentFolder.Name
    StoreName = CurrentFolder.Store.DisplayName
    
    Report = Report & TabChars & FolderName & " (Store: " & StoreName & ")" & vbCrLf
    
    For Each SubFolder In CurrentFolder.Folders
        Call RecurseFolders(SubFolder, TabChars & vbTab, Report)
    Next SubFolder
End Sub
Sub CreateReportEmail(Title As String, Report As String)
    Dim aMail As MailItem
    
    Set aMail = Application.CreateItem(olMailItem)
        
    aMail.Subject = Title
    aMail.Body = Report
    
    aMail.Display
End Sub

4. Press the F5 key on the keyboard to start running the VBA code.

5. Now a Macro dialog box pops up, please click the Run button.

6. Wait for the Macro running. Then the list of all your email folders is listed out in a created new message window immediately. You can easily print it out. See screenshot:

Note: This VBA code can be applied to Outlook 2007, 2010 and 2013.


Kutools for Outlook - Brings 100 Advanced Features to Outlook, and Make Work Much Easier!

  • Auto CC/BCC by rules when sending email; Auto Forward Multiple Emails by custom; 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 in seconds; Auto Add Greeting when reply; Add Date into subject...
  • Attachment Tools: Manage All Attachments in All Mails, Auto Detach, Compress All, Rename All, Save All... Quick Report, Count Selected Mails...
  • Powerful Junk Emails by custom; Remove Duplicate Mails and Contacts... Enable you to do smarter, faster and better in Outlook.
shot kutools outlook kutools tab 1180x121
shot kutools outlook kutools plus tab 1180x121
 
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.