Discussion Locked

VBA code to display folders hierarchy in

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Could someone show me the source code for displaying a hierarchy tree of folders in Outlook 2000. I'm not looking for anything fancy just to get a list of folders to the debug window. Something like:
Mailbox - user
Calendar
Contacts
...
Public Folders
...

2 replies

by zalo9

Option Explicit

Private Sub CommandButton1_Click()
Dim golApp As Outlook.Application
Dim gnspNameSpace As Outlook.NameSpace
Dim myfolder As Outlook.MAPIFolder
Dim newFolder As Outlook.MAPIFolder
Dim j As Integer

Set golApp = New Outlook.Application ' Application object.
Set gnspNameSpace = golApp.GetNamespace("MAPI") ' Namespace object.

With gnspNameSpace.Folders
Set myfolder = .GetFirst
Call GetFolderNames(myfolder, 0)
For j = 2 To .Count
Set newFolder = .GetNext
Call GetFolderNames(newFolder, 0)
Next
End With
End Sub

Sub GetFolderNames(fldFolder As Outlook.MAPIFolder, level As Integer)Dim objItem As Object
Dim iTab As Integer

On Error Resume Next
For iTab = 1 To level
Debug.Print " ";
Next iTab
Debug.Print fldFolder.Name & " (" _
& fldFolder.Items.Count & " items)"
If fldFolder.F

This discussion is closed to new replies.