HOWTO:: Display Outlook Folder NamesLast reviewed: September 26, 1997Article ID: Q174141 |
The information in this article applies to:
Enterprise Editions for Windows, version 5.0
SUMMARYThe following code sample demonstrates how to print the names of all folders grouped under a specified Outlook folder. The sample assumes that the Microsoft Outlook mail client is installed.
MORE INFORMATIONThe code below uses a recursive routine to iterate through a mail folder to produce a list of all its sub-folders in the Immediate Window.
Step-by-Step Example
constant in the code below as appropriate and Execute.) Option Explicit Private Sub Main() Dim olMAPI As Outlook.NameSpace Dim Folder As Outlook.MAPIFolder Const FOLDER_TO_OPEN = "Mailbox - John Doe" '// Modify as appropriate Set olMAPI = GetObject("", "Outlook.application").GetNamespace("MAPI") Call PrintFolderNames(olMAPI.Folders(FOLDER_TO_OPEN), "- >") Set olMAPI = Nothing End Sub Sub PrintFolderNames(tempfolder As Outlook.MAPIFolder, a$) Dim i As Integer If tempfolder.Folders.Count Then Debug.Print a$ & " " & tempfolder.Name For i = 1 To tempfolder.Folders.Count Call PrintFolderNames(tempfolder.Folders(i), a$ & "- >") Next i Else Debug.Print a$ & " " & tempfolder.Name End If End SubNOTE: The sample code in this article works only when the FOLDER_TO_OPEN is set to a folder you can open, such as your own folder or the public folder. Otherwise a runtime error is generated. Keywords : vb5all vb5howto Version : WINDOWS:5.0 Platform : WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |