Author StringCat.com
Sub EnumerateFoldersInStores()
' store is a pst file
Dim App As New Outlook.Application
Dim Stores As Outlook.Stores
Dim Store As Outlook.Store
Dim Root As Outlook.Folder
On Error Resume Next
' all pst files shown by Outlook session
Set Stores = App.Session.Stores
'loop over folders in each pst file
For Each Store In Stores
Set Root = Store.GetRootFolder
EnumerateFolders Root
Next
End Sub
Private Sub EnumerateFolders(ByVal Root As Outlook.Folder)
'recursive function
Dim Folders As Outlook.Folders
Dim Folder As Outlook.Folder
Dim Foldercount As Integer
On Error Resume Next
Set Folders = Root.Folders
Foldercount = Folders.Count
If Foldercount Then
For Each Folder In Folders
Folder.ShowItemCount = olShowTotalItemCount
EnumerateFolders Folder
Next
End If
End Sub