Solved

Outlook / VBA / Folder Tree

Posted on 2004-09-02
3
1,721 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 250 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

Create Professional Looking Email Signatures

Create "Professional HTML Email Signatures" with ease.
7 Day Money Back Guarantee if not 100% Satisfied.
Affordable - Try it out for 7 Days Totally Risk Free.
Installers provided for over 45 Email clients.
Both Windows & MAC Supported.
Highly Recommended!

Question has a verified solution.

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

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
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…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

732 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