Skip to main content

How to get list of folders in Outlook?

Author: Siluvia Last Modified: 2014-09-26

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 Microsoft Office, Making Work a Breeze
Unlock Kutools for Outlook's free version now and enjoy over 70 features with unlimited access forever
Boost your Outlook 2021 - 2010 or Outlook 365 with these advanced features. Enjoy 70+ powerful features and elevate your email experience!

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.


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!

🤖 Kutools AI : Instant pro emails with AI magic--one-click to genius replies, perfect tone, multilingual mastery. Transform emailing effortlessly! ...

📧 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 ProBatch 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 ...

Instantly unlock Kutools for Outlook with a single click—permanently free. Don't wait, download now and boost your efficiency!

kutools for outlook features1 kutools for outlook features2
 

 

 

Comments (2)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
For get the size of the folders how do you do it?
This comment was minimized by the moderator on the site
Working perfect with OLK 365, Thank you!
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations