• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Print a list of your Outlook folders

Slipstick Systems

› Developer › Print a list of your Outlook folders

Last reviewed on April 25, 2024     16 Comments

Use this VBA macro to get a list of the folder names in your data file, printing it to the Immediate window and inserting it into a new message form.

If you want the full path within the data file, use this line:
strFolders = strFolders & vbCrLf & olTempFolderPath

If you want just the folder names, use
strFolders = strFolders & vbCrLf & olTempFolder

The folder list will be in the following format.
print a folder list in Outlook

While I don't have subfolders in the data file I printed out, the printout will include any subfolders and list the full path.

Updated March 14 2015 to include the item count after the folder name, like this:
\\Account Manager\Inbox\Completed 95.

Macro to print a list of folders in an Outlook data file

To use, open the VB Editor by pressing Alt+F11. Right-click on Project1 and Insert > Module. Paste the following code into the module then run the macro.

When you run the macro, the folder picker dialog will come up for you to pick the data file (or subfolder) to use as the top level folder for the printout. If you want to list all folders in your data file, choose the top of the data file, which is usually your email address.

Public strFolders As String
 
Public Sub GetFolderNames()
    Dim olApp As Outlook.Application
    Dim olSession As Outlook.NameSpace
    Dim olStartFolder As Outlook.MAPIFolder
    Dim lCountOfFound As Long
 
    lCountOfFound = 0
      
    Set olApp = New Outlook.Application
    Set olSession = olApp.GetNamespace("MAPI")
      
     ' Allow the user to pick the folder in which to start the search.
    Set olStartFolder = olSession.PickFolder
      
     ' Check to make sure user didn't cancel PickFolder dialog.
    If Not (olStartFolder Is Nothing) Then
         ' Start the search process.
        ProcessFolder olStartFolder
    End If
     
' Create a new mail message with the folder list inserted
Set ListFolders = Application.CreateItem(olMailItem)
  ListFolders.Body = strFolders
  ListFolders.Display

' To create a text file you can open in Excel, use this
strPath = Environ("USERPROFILE") & "\Documents\OutlookFolders.csv"
  Debug.Print strPath
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set Fileout = fso.CreateTextFile(strPath, True, False)
    Fileout.WriteLine strFolders
      
' clear the string so you can run it on another folder
  strFolders = ""
End Sub
  
Sub ProcessFolder(CurrentFolder As Outlook.MAPIFolder)
         
    Dim i As Long
    Dim olNewFolder As Outlook.MAPIFolder
    Dim olTempFolder As Outlook.MAPIFolder
    Dim olTempFolderPath As String
     ' Loop through the items in the current folder.
    For i = CurrentFolder.Folders.Count To 1 Step -1
          
        Set olTempFolder = CurrentFolder.Folders(i)
          
        olTempFolderPath = olTempFolder.FolderPath

     ' Get the count of items in the folder
         olCount = olTempFolder.Items.Count

     'prints the folder path and name in the VB Editor's Immediate window
         Debug.Print olTempFolderPath & " " & olCount
           
        ' prints the folder name only
         ' Debug.Print olTempFolder
          
         ' create a string with the folder names.
         ' use olTempFolder if you want foldernames only
         strFolders = strFolders & vbCrLf & olTempFolderPath & vbTab & olCount
         
        lCountOfFound = lCountOfFound + 1
          
    Next
     ' Loop through and search each subfolder of the current folder.
    For Each olNewFolder In CurrentFolder.Folders
          
         'Don't need to process the Deleted Items folder
        If olNewFolder.Name <> "Deleted Items" Then
            ProcessFolder olNewFolder
        End If
          
    Next
      
End Sub

 

Include the Folder Size

If you want to include the folder size, you need to get the size of each item in the folder and add them together.

To use this macro, replace the ProcessFolder macro above with this one.

The printout will look like this:

\\my@address.com\Inbox\1Test 151 34534 KB
\\my@address.com\Inbox\SO Mailer 361 44115 KB
\\my@address.com\Inbox\.Completed 1 3115 KB

It will take longer to run the macro using this version of the ProcessFolder macro.

Sub ProcessFolder(CurrentFolder As Outlook.MAPIFolder)
         
    Dim i As Long
    Dim olNewFolder As Outlook.MAPIFolder
    Dim olTempFolder As Outlook.MAPIFolder
    Dim olTempFolderPath As String
    
    Dim objItems As Items
    Dim objItem As Object
    Dim intSize As Long
  
     ' Loop through the items in the current folder.
    For i = CurrentFolder.Folders.Count To 1 Step -1
          
        Set olTempFolder = CurrentFolder.Folders(i)
          
        olTempFolderPath = olTempFolder.FolderPath

    
      Set objItems = olTempFolder.Items
     ' Get the count of items in the folder
         olcount = objItems.Count
' reset folder size so you don't have a running total
      intSize = 0
    ' Get the size
      For Each objItem In objItems
        Debug.Print olcount, objItem.Subject, objItem.Size
            intSize = intSize + objItem.Size
        Next
        
       ' convert to KB
       kbSize = Int(intSize / 1024) & " KB"

     'prints the folder path, name, and size in the VB Editor's Immediate window
         Debug.Print olTempFolderPath, olcount, kbSize
           
     ' create a string with the folder names.
         strFolders = strFolders & vbCrLf & olTempFolderPath & vbTab & olcount & vbTab & kbSize
         
        lCountOfFound = lCountOfFound + 1
          
    Next
     ' Loop through and search each subfolder of the current folder.
    For Each olNewFolder In CurrentFolder.Folders
          
         'Don't need to process the Deleted Items folder
        If olNewFolder.Name <> "Deleted Items" Then
            ProcessFolder olNewFolder
        End If
          
    Next
      
End Sub

 

Include Total Folder Count

This version of the macro includes the total folder count at the top of the list in the Outlook message form.

It does not include hidden system folders (there are a lot of hidden folders, especially in Exchange mailboxes, including shared contacts and calendar folders) or RSS subscription or Sync issues folders in the list or folder count.

Note: folders in pst files do not have a created date property. That is limited to IMAP and Exchange ost files.

Public strFolders As String
Public TotalFolders As Long
Public Sub GetFolderNames()
    Dim olApp As Outlook.Application
    Dim olSession As Outlook.NameSpace
    Dim olStartFolder As Outlook.MAPIFolder
    Dim lCountOfFound As Long
 
    lCountOfFound = 0
    TotalFolders = 0
    Set olApp = New Outlook.Application
    Set olSession = olApp.GetNamespace("MAPI")
      
     ' Allow the user to pick the folder in which to start the search.
    Set olStartFolder = olSession.PickFolder
      
     ' Check to make sure user didn't cancel PickFolder dialog.
    If Not (olStartFolder Is Nothing) Then
         ' Start the search process.
        ProcessFolder olStartFolder
    End If
     
' Create a new mail message with the folder list inserted
Set ListFolders = Application.CreateItem(olMailItem)
  ListFolders.Body = TotalFolders & " Folders in the mailbox" & vbCrLf & strFolders
  ListFolders.Display

'' To create a text file you can open in Excel, use this
'strPath = Environ("USERPROFILE") & "\Documents\OutlookFolders.csv"
'  Debug.Print strPath
'    Set fso = CreateObject("Scripting.FileSystemObject")
'    Set Fileout = fso.CreateTextFile(strPath, True, False)
'    Fileout.WriteLine strFolders
      
' clear the string so you can run it on another folder
  strFolders = ""
End Sub
  
Sub ProcessFolder(CurrentFolder As Outlook.MAPIFolder)
         
    Dim i As Long
    Dim olNewFolder As Outlook.MAPIFolder
    Dim olTempFolder As Outlook.MAPIFolder
    Dim olTempFolderPath As String
    Dim oPA As Outlook.propertyAccessor
    Dim PropName, Value, FolderType As String
    PropName = "http://schemas.microsoft.com/mapi/proptag/0x10F4000B"
    
     ' Loop through the items in the current folder.
    
    For i = CurrentFolder.Folders.Count To 1 Step -1
    Set olTempFolder = CurrentFolder.Folders(i)

' Skip RSS and Sync issues folders
    If InStr(olTempFolder.FolderPath, "RSS Subscriptions") > 0 Then GoTo Nextfolder
    If InStr(olTempFolder.FolderPath, "SyncIssues") > 0 Then GoTo Nextfolder

' Skip Hidden folders
' #####
  Set oPA = olTempFolder.propertyAccessor
  Value = oPA.GetProperty(PropName)
   If Value = "" Then Value = "None"
  Debug.Print Value
  On Error Resume Next
  
  If Value = "True" Then GoTo Nextfolder
' #####
' end skip hidden folders

TotalFolders = TotalFolders + 1
   Debug.Print "folder count", TotalFolders
   olTempFolderPath = olTempFolder.FolderPath

' Get the count of items in the folder
    olCount = olTempFolder.Items.Count

'prints the folder path and name in the VB Editor's Immediate window
    Debug.Print olTempFolderPath & " " & olCount
          
    ' create a string with the folder names.
    ' use olTempFolder if you want foldernames only
    strFolders = strFolders & vbCrLf & olTempFolderPath & vbTab & olCount
    
   lCountOfFound = lCountOfFound + 1
Nextfolder:

Next
 ' Loop through and search each subfolder of the current folder.
For Each olNewFolder In CurrentFolder.Folders
      
     'Don't need to process the Deleted Items folder
    If olNewFolder.Name <> "Deleted Items" Then
        ProcessFolder olNewFolder
    End If
      
Next
      
End Sub

How to use the macros on this page

First: You need to have macro security set to the lowest setting, Enable all macros during testing. The macros will not work with the top two options that disable all macros or unsigned macros. You could choose the option Notification for all macros, then accept it each time you restart Outlook, however, because it's somewhat hard to sneak macros into Outlook (unlike in Word and Excel), allowing all macros is safe, especially during the testing phase. You can sign the macro when it is finished and change the macro security to notify.

To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, look at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

The macros on this page should be placed in a module.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

Print a list of your Outlook folders was last modified: April 25th, 2024 by Diane Poremsky

Related Posts:

  • Delete folders using a VBA Macro or PowerShell
  • How to Hide or Delete Outlook's Default Folders
  • Apply a View to a Folder using a Macro
  • Macro to file Outlook email by sender's display name

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
16 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Isis (@guest_220970)
March 7, 2024 4:08 pm
#220970

This worked perfectly! Thank you so much!

0
0
Reply
Jim Franklin (@guest_220961)
February 29, 2024 5:37 am
#220961

Hi Diane,

Just stumbled across your tool and thought it was perfect for what I need. A brilliant tool.

Unfortunately I am getting a Not Defined error for Outlook.MAPIFolder when I try and run it. Upon investigation it appears MAPIFolder has now been deprecated? (I am using Office 365.)

Any idea what it should be replaced with?

Thanks,
Jim

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Jim Franklin
March 7, 2024 8:41 pm
#220972

Try Folder - but mapifolder should work. (It works here)

Which line is it dying on?

0
0
Reply
Sen (@guest_220162)
March 15, 2023 1:43 pm
#220162

Larger data sets may require;
Dim intSize As LongLong

0
0
Reply
Falcios (@guest_206523)
May 15, 2017 5:15 am
#206523

Great post.

Is there a way to include code to cycle through all PSTs instead of clicking
each one individually?

Also, is there VBA code or utility for scanpst.exe to cycle through all psts
instead of selecting individual PSTs?

Thanks in advance.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Falcios
May 15, 2017 9:15 am
#206525

it would be possible to go through all pst to 'do sometihng' - i have a macro that does it for color categories at https://www.slipstick.com/developer/get-color-categories-and-restore-them-using-vba/#stores - you'd change what you do within the for each store loop.

Scanpst: I'm not aware of a way to run it on all psts is one step - some commercial products support it (Datanumen does, i didn't check the others) https://www.slipstick.com/problems/pst-repair/repair-a-damaged-personal-folders-pst-file/

0
0
Reply
Chandana (@guest_201686)
September 19, 2016 12:05 pm
#201686

Excellent script. Works like a charm with OL 2010 and very helpful. Thanks a lot.

0
0
Reply
Lori (@guest_197758)
April 11, 2016 11:28 am
#197758

Awesome Tool - thank you!

0
0
Reply
Jamie Klein (@guest_196748)
February 25, 2016 11:54 pm
#196748

Just opens a blank email.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Jamie Klein
February 26, 2016 11:35 am
#196761

Do you know what version of Outlook you're using?

0
0
Reply
Glen (@guest_193959)
October 13, 2015 4:56 pm
#193959

What a wonderful WONDERFUL tool, made me look REALLY GOOD~~~~~~

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 19

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
  • Classic Outlook is NOT Going Away in 2026
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Classic Outlook is NOT Going Away in 2026

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment