print-list-of-outlook-folders with sort posibility

Status
Not open for further replies.

Witzker

Senior Member
Outlook version
Outlook 2019 64-bit
Email Account
POP3
Hi Diane
I found your great macro to printout the folder structure of OL

Print a list of your Outlook folders (slipstick.com)

As I have 3 synct outlooks (SimpleSysn) and the tool is really good as time goes by with some errors shutdowns etc. there are sometimes a lot of duplicates in the different outlooks.

To go quickly through the different Ols your tool is very helpful.

BUT if it would be possible to sort the output of the folder list like it is displayed in OL It would be super PERFECT!

How is it possible to sort the output?

Top folder
Topfolder/- Axxxx
Topfolder/- Bxxxx
Topfolder/ Axxxx
Topfolder/ Bxxxx
Topfolder/ Bxxxx / -Axxx
Topfolder/ Bxxxx / Axxx
and so on

I use "-" before the NAME to get important Folders to be listed before the others beginning with A in alphabetic order as Outlook sorts the folders.

I hope you can have a look at the macro and help me.

Code:
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
      
' 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 & " " & 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
 
Last edited:
You need to add the folder names to an array then sort the array. There are some for Excel and Word that could be tweaked. Or you could write it to an excel file (or copy and paste from the list in outlook) then sort using excel features. This would be easier if you wanted to do it all with VBA.
 
Or you could write it to an excel file (or copy and paste from the list in outlook) then sort using excel features. This would be easier if you wanted to do it all with VBA.
That's it !
You are right THX
---------------------------------
How to set status to solved ??
 
Use this in place of the code that save the Outlook message (or in addition to ) - it writes it to a CSV - open in Excel and use Text to columns to separate the message count from the folder name.

If you use tab instead of space (or remove the item count), spaces in folder names won't be a problem when you use text to columns in Excel - this is the processfolder sub:
' create a string with the folder names.
' use olTempFolder if you want foldernames only
strFolders = strFolders & vbCrLf & olTempFolderPath & vbTab & olCount

Code:
strPath = Environ("USERPROFILE") & "\Documents\OutlookFolders.csv"
  Debug.Print strPath
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set Fileout = fso.CreateTextFile(strPath, True, False)
    Fileout.WriteLine strFolders
 
Last edited:
THX
in the meantime I found This:
Code:
Option Explicit

Dim excApp As Object, _
         excWkb As Object, _
         excWks As Object, _
         lngRow As Long

Sub EnumerateFolders()
    Dim olkSto As Outlook.Store
    Set excApp = CreateObject("Excel.Application")
    Set excWkb = excApp.Workbooks.Add
    Set excWks = excWkb.Worksheets(1)
    With excWks
        .Cells(1, 1) = "Path"
        .Cells(1, 2) = "Folder"
    End With
    lngRow = 2
    For Each olkSto In Session.Stores
        ProcessFolder olkSto.GetRootFolder
    Next
    excWks.Columns("A:B").AutoFit
    excApp.Visible = True
    Set excWks = Nothing
    Set excWkb = Nothing
    Set excApp = Nothing
    Set olkSto = Nothing
End Sub

Sub ProcessFolder(olkFol As Outlook.Folder)
    Dim olkSub As Outlook.Folder
    excWks.Cells(lngRow, 1) = olkFol.FolderPath
    excWks.Cells(lngRow, 2) = olkFol.Name
    lngRow = lngRow + 1
    For Each olkSub In olkFol.Folders
        ProcessFolder olkSub
    Next
    Set olkSub = Nothing
End Sub

Puts the list directly in an *XLS File
BUT NO Chooser which yours have

And Mainly! The items in Folder are not shown in the list!!

Maybe you could be so kind and edit Your macro (READY to USE) with chooser and Items per folder to write directly to XLS File?
(as I noticed many views on this thread & you can update this on Your Page)
What do you think?;)
THX in advance!
 
Last edited:
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Diane Poremsky Print a list of your Outlook folders Using Outlook 0
D Use Outlook 2003 embedded imaged cannot print from the mail preview list Using Outlook 4
B Print list of previously sent recipients Using Outlook 1
R how do I print a list of folders/subfolders in Inbox Outlook VBA and Custom Forms 1
G Print email attachments when hit subfolder Outlook VBA and Custom Forms 1
U Outlook not responding when trying to print Emails Using Outlook 6
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
S Cannot print Contacts Using Outlook 7
G print attachment straight away; working script edit not working Outlook VBA and Custom Forms 0
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
S CONTACT FIELD PRINT ORDER Outlook VBA and Custom Forms 1
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
B Outlook 2016 Outlook crashes when trying to print certain emails Using Outlook 5
M Batch print without appended trail of repeated e Using Outlook 2
M Custom Calendar Print Suggestions? Using Outlook 0
M Print email and, attachments sent in hyperlinks in the email Outlook VBA and Custom Forms 2
D Print attachments automatically and moves the mail to a new folder Outlook VBA and Custom Forms 9
A Day view - print appointment details Using Outlook 1
I print calendar without subject and details Using Outlook 1
D Print Attachments only in selected emails using a macro Outlook VBA and Custom Forms 3
oliv- property "is printed" or catching print events Outlook VBA and Custom Forms 2
I Print Automatically Attachments Outlook VBA and Custom Forms 3
Diane Poremsky Combine and Print Multiple Outlook Calendars Using Outlook 0
R Print email message and attachment in order Outlook VBA and Custom Forms 2
L Outlook 2002: HTML Emails Will Not Print: Please Help Using Outlook 0
A Print first page of a new email Outlook VBA and Custom Forms 7
Diane Poremsky Print Monthly or Work Week Calendars Using Outlook 0
Diane Poremsky No drop down calendars in Outlook 2010 Print Options Using Outlook 0
Diane Poremsky Print Monthly or Work Week Calendars Using Outlook 0
S Macro to print & move selected emails? Using Outlook 3
J Auto print PDF attachments as they arrive with certain words in subject Outlook VBA and Custom Forms 3
H Problems With Outlook 2013 VBA To Send and Print an email Outlook VBA and Custom Forms 1
D Outlook 2013 Categories won't print In color Using Outlook 2
G Calendar monthly view - Print just 3 weeks Using Outlook 5
R Can't modify Outlook view font with IE anymore (even though IE still affects print font) Using Outlook 5
M Print Attachments from another mailbox (not default) Outlook VBA and Custom Forms 2
E Outlook VBA to print attached Pdf to a fax printer and assign fax number Using Outlook 0
L Outlook 2010 Quick Print Attachment, nothing happend Using Outlook 0
C automatically print attachments Using Outlook 4
J Automatically Print PDF When They Are Received Using Outlook 4
M button to send and print emails Using Outlook 26
S How to print ONLY first line of appointments in month view? Using Outlook 1
M print free/busy schedule of an user Using Outlook 2
O For Outlook 2007 - VBA to print attachments Using Outlook 1
W Cannot print Outlook 2007 emails Using Outlook 2
R problem with incomming e-mail I am unable to print full e-mail letter Using Outlook 1
M Custom print contacts Using Outlook 2
E Can't print from Outlook on wifi network Using Outlook 0
E can't print some retail discount coupons Using Outlook 7
J calendar print setup in outlook 2010 Using Outlook 1

Similar threads

Back
Top