In my Folder Pane example above, I only list three standard folders: “Inbox”, “Drafts” and “Deleted Items”. There are other standard folders and you can create as many folders of your own as you wish. Some people create folders under Inbox but I prefer to create new folders at the same level as Inbox. Your folders can have sub-folders which can have their own sub-folders to any depth.
The following macro will produce a listing of the form:
A
A1
A2
A3
B
B1
B2
C
C1
C2
C3
C4
where A, B and C are stores and A1, B1, C1 and so on are folders within A, B and C. If A1, B1, C1 and so on have sub-folders, they will not be listed by this macro. Accessing more deeply nested folders will be covered in the next part of this tutorial.
Sub ListStoresAndTopLevelFolders()
Dim FldrCrnt As Folder
Dim InxFldrCrnt As Long
Dim InxStoreCrnt As Long
Dim StoreCrnt As Folder
With Application.Session
For InxStoreCrnt = 1 To .Folders.Count
Set StoreCrnt = .Folders(InxStoreCrnt)
With StoreCrnt
Debug.Print .Name
For InxFldrCrnt = .Folders.Count To 1 Step -1
Set FldrCrnt = .Folders(InxFldrCrnt)
With FldrCrnt
Debug.Print " " & .Name
End With
Next
End With
Next
End With
End Sub