This is Outlook VBA code adapted from my forthcoming Outlook 2007 book. It puts a list in the Immediate window. You could adapt it to write the information to a file, a message, etc. Note that ProcessFolder is recursive.
Dim mlngItemCount As Long
Dim mlngFolderCount As Long
Dim mstrList As String
Sub ListAllFolders()
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objMsg As Outlook.MailItem
mlngItemCount = 0
mlngFolderCount = 0
mstrList = ""
Set objOL = Application
Set objNS = objOL.Session
For Each objFolder In objNS.Folders
Call ProcessFolder(objFolder)
mstrList = mstrList & vbCrLf
Next
Set objMsg = objOL.CreateItem(olMailItem)
mstrList = mstrList & vbCrLf & _
"Total folders in Outlook = " & _
Format(mlngFolderCount, "###,###") & _
vbCrLf & "Total items in Outlook = " & _
Format(mlngItemCount, "###,###")
objMsg.Body = mstrList
objMsg.Display
Set objOL = Nothing
Set objNS = Nothing
Set objFolder = Nothing
End Sub
Sub ProcessFolder(startFolder As Outlook.MAPIFolder)
Dim objFolder As Outlook.MAPIFolder
On Error Resume Next
mstrList = mstrList & vbCrLf & startFolder.FolderPath & _
vbTab & startFolder.Items.Count
mlngItemCount = mlngItemCount + startFolder.Items.Count
mlngFolderCount = mlngFolderCount + 1
For Each objFolder In startFolder.Folders
Call ProcessFolder(objFolder)
Next
Set objFolder = Nothing
End Sub
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers