Solved

Outlook / VBA / Folder Tree

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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 …
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…

735 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