[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Outlook / VBA / Folder Tree

Posted on 2004-09-02
3
Medium Priority
?
1,736 Views
Last Modified: 2008-02-01
I'm trying to design a folder list window.  I have it working however it is very slow.  My thought is that there must be some way to add a outlook folder and capture the selected item rather then using a ListBox.  

Right now, here is what I am doing:
On the form load, it runs the following code

Private Sub UserForm_Activate()

    Dim objApp As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim colFolders As Outlook.Folders
    Dim objFolder As Outlook.MAPIFolder
    Dim arrFolders() As String
   
    Set objApp = CreateObject("Outlook.Application")
    Set objNS = objApp.GetNamespace("MAPI")
    UserForm1.arrList.Clear
    UserForm1.FolderList.Clear
    Call GetFolder(objNS.GetDefaultFolder(olFolderInbox).EntryID, "", "")

End Sub

Public Function GetFolder(strFolder As String, strPrefix As String, strSpacing As String) As MAPIFolder
   
    Dim objApp As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim colFolders As Outlook.Folders
    Dim objFolder As Outlook.MAPIFolder
    Dim arrFolders() As String
   
    Set objApp = CreateObject("Outlook.Application")
    Set objNS = objApp.GetNamespace("MAPI")
   
    Set MyFolder = objNS.GetFolderFromID(strFolder)
   
    numitems = MyFolder.Folders.Count
   
    For I = 1 To numitems
        UserForm1.arrList.AddItem MyFolder.Folders.Item(I).EntryID
        UserForm1.FolderList.AddItem strSpacing & " " & MyFolder.Folders.Item(I)
        If MyFolder.Folders.Item(I).Folders.Count > 0 Then
            Call GetFolder(MyFolder.Folders.Item(I).EntryID, MyFolder.Folders.Item(I) & " > ", strSpacing & " - -")
        End If
    Next

End Function


It works great, however its very slow.

Thoughts would be greatly appreciated.
0
Comment
Question by:DeYoungJD
[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
3 Comments
 
LVL 13

Accepted Solution

by:
stefri earned 1000 total points
ID: 11968932
if you want to select a folder from code (as you do in Inbox) let the user select it with:

The PickFolder method displays the Pick Folder dialog box. This is a modal dialog box which means that code execution will not continue until the user either selects a folder or cancels the dialog box. Returns a MAPIFolder object corresponding to the folder that the user selects in the dialog box. Returns Nothing when the dialog box is canceled by the user.

expression.PickFolder

expression   Required. A NameSpace object.

Stefri
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

650 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