Solved

Enumerating Outlook folders.

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

756 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