Solved

Outlook / VBA / Folder Tree

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
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.
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…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now