Solved

Enumerating Outlook folders.

Posted on 2001-06-26
2
349 Views
Last Modified: 2012-06-21
Does anyone have any code that will populate a treeview control with the folder structure of an outlook profile? My whole goal is to be able to traverse the folder structure that a user has in thier outlook profile without starting (visibly) outlook.
0
Comment
Question by:raycass
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 200 total points
ID: 6230387
This example needs a reference to Microsoft Outlook Object Library to be added to the project.

Private Sub Command1_Click()
    Dim appOutlook As Outlook.Application
    Dim blnCloseIt As Boolean
    Dim fldFolder As MAPIFolder
    Dim tvnFolder As Node
    On Error Resume Next
    Set appOutlook = GetObject(, "Outlook.Application")
    If appOutlook Is Nothing Then
        Set appOutlook = CreateObject("Outlook.Application")
        blnCloseIt = True
    End If
    With appOutlook.GetNamespace("MAPI")
        Set tvnFolder = TreeView1.Nodes.Add(, , "Mapi", "Mapi Folders")
        tvnFolder.EnsureVisible
        For Each fldFolder In .Folders
            IterateFolders "Mapi", fldFolder, TreeView1
        Next
    End With
    If blnCloseIt Then appOutlook.Quit
    Set appOutlook = Nothing
End Sub

Private Sub IterateFolders(Parent As String, CurrentFolder As MAPIFolder, TView As TreeView)
    Dim fldFolder As MAPIFolder
    Set tvnFolder = TView.Nodes.Add(Parent, tvwChild, CurrentFolder.EntryID, CurrentFolder.Name)
    tvnFolder.EnsureVisible
    For Each fldFolder In CurrentFolder.Folders
        IterateFolders CurrentFolder.EntryID, fldFolder, TView
    Next
End Sub
0
 
LVL 1

Author Comment

by:raycass
ID: 6241010
TimCottee, You rock!

Thanks for the excellet example!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question