Solved

Enumerating Outlook folders.

Posted on 2001-06-26
2
346 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now