Print a List of Outlook Mail Folders

Copper Contributor

My boss has an extensive list of folders in his Outlook - literally hundreds of folders he saves his emails to. I am trying to come up with a leaner approach to his email hording and would like to have a list of all the folders so I can attempt to reorganize and provide some project guidelines for how he approaches saving his emails. I know this is not a function built into outlook, and I have researched it and most answers require an understanding of coding which I am not versed in. Does anyone know how to accomplish this, by whatever methodology (except typing out the list), even if coding is involved (so long as it's easy to understand)? Thank you!

10 Replies

@jamesstjohn,

 

I am an independent advisor responding to this inquiry.

 

I found two great articles with VBA codes to run a macro to print your list of Outlook Folders with | without item count. 

 

https://www.extendoffice.com/documents/outlook/4099-outlook-print-list-of-folders.html

 

And, @diane_poremsky of SlipStick System has a good article as well.

https://www.slipstick.com/developer/print-list-of-outlook-folders/

 

If you find this information helpful, please mark it as the best answer or like it, which will help others with the same question.

 

And, wishing with you well with your project. 

 

/Teresa

#traccreations4e

 

@Teresa_Cyrus - thanks for the articles! I tried this, but I keep getting an error saying VBA compile error - Invalid Outside Procedure. I assume the people who wrote the code checked it, so it can't be bad coding. Would this have anything to do with maybe our network email and the parameters don't take this into consideration, that the code is written for single users NOT using not on networked email? I am not at all versed in this and am merely spit balling, but if you have other ideas I am all ears! Thank you!

@jamesstjohn 

 

Sorry that you are having trouble.  I ran the script, and it works.

1) First, try pasting the code again. It sounds like maybe a line of code is missing. It is located at the bottom of this message. If it fails again, see the next bullet.

 

2) Also, can you check your macro security settings? Although the article recommended changing this setting, I ran the macro without making any changes. 

  • File | Options | Trust Center
    Click on Trust Center Settings
    Teresa_Cyrus_0-1661391891475.png

    Click on Macro Settings

    Teresa_Cyrus_1-1661391971152.png

     

    Please change it to Notification for all macros.  

My recommendation is once your run the macro successfully, repeat the steps above and select original macro security settings.

Here is the code again.

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


/Teresa

Expand all their folders an make several screenshots. Then combine the screenshots in any graphical editor to get the whole picture (it will be really big I guess),

>>
I keep getting an error saying VBA compile error - Invalid Outside Procedure
<<
Did you copy the entire macro or miss a line or two at the end? That will cause the error. Did it highlight any of the lines?

Did you paste it in to ThisOutlookSession or into a new module? It should work in either, but pasting it in a module is recommended, especially if you have other macros.


I copied the macro exactly, attempted the process at least 3 times, all with the same error. Not sure what the cause of the issue is, but I am continuing to research this issue and hopefully find the cause of failure.
I tired this method as well but Adobe would transpose the screen shots into viable text. I will attempt with other apps that can manage the same function.
Still having issues...trying to research this and determine where the failure is - user error or networked Outlook mail access from an indirect access source. I'll keep looking...

@jamesstjohn  

The macro works here, in a new module by itself. 

 

DianePoremsky_0-1661961991213.png

 

Thanks for the visuals! I'll give it a go and get back to you.
Thank you for all your interactions and support; I truly appreciate it!