?
Solved

Enumerating Outlook folders.

Posted on 2001-06-26
2
Medium Priority
?
354 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 800 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

800 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