Solved

Outlook / VBA / Folder Tree

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
Changing a few Outlook Options can help keep you organized!
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…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

707 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