Consulting

Results 1 to 4 of 4

Thread: List foldersn outlook

  1. #1
    VBAX Regular
    Joined
    Sep 2005
    Posts
    78
    Location

    List folders in outlook

    I am writing code to redirect mails from perticular EmailAddress.

    For that i am giving user a form in which all the folders in outlook will be listed.

    I am not getting the code to do this.

    I can do this if i want to list folders from perticular folder like inbox by this :
    [VBA] Set myOlApp = CreateObject("Outlook.Application")
    Set name = myOlApp.GetNamespace("MAPI")
    Set fldFolder = name.Folders("olinbox")
    'For Each prfolder In fldFolder

    Set objApp = CreateObject("Outlook.Application")
    Set objNS = objApp.GetNamespace("MAPI")

    Call GetFolderInfo(fldFolder)
    [/VBA]
    GetFolderInfo is listing folders in fldfolder.

    But i want to check for all folders in outlook.(like folders in outbox, inbox....)

    How can i list them?

  2. #2
    The Folders property of your NameSpace object contains the root of all your Outlook folders as a MAPIFolder named "Personal Folders." In turn, the Folders property of that MAPIFolder contains the MAPIFolder objects representing subfolders of Personal Folders, which includes Inbox, Outbox, Sent Items, Contacts, Journal, etc. The real trick is handling subfolders, especially nested ones. This is where having the procedure call itself can be quite handy.

    Let's say your userform has a listbox named "listFolders". To identify each folder, we'll store the EntryID of the MAPIFolder in a bound, hidden (0"-width) column while we display the name in a second column. The following code would generate the list for you when you click on a button named CommandButton1:
    [VBA]
    Private Sub CommandButton1_Click()
    Dim NS As NameSpace
    Set NS = Application.GetNamespace("MAPI")
    listSubFolders NS.Folders(1)
    End Sub
    Private Sub listSubFolders(f As MAPIFolder, Optional i As Integer)
    Dim x As MAPIFolder
    For Each x In f.Folders
    ' Optional test for email type folders only
    ' If x.DefaultItemType = olMailItem Then
    listFolders.AddItem x.EntryID
    listFolders.Column(1, listFolders.ListCount - 1) = String(i, "-") & x.Name
    If x.Folders.count > 0 Then listSubFolders x, i + 1
    ' End If
    Next
    End Sub
    [/VBA]

    When the user selects a folder, you can programatically obtain the referenced MAPIFolder by calling NS.GetFolderFromID(listFolders) where NS is your NameSpace object.

  3. #3
    VBAX Regular
    Joined
    Sep 2005
    Posts
    78
    Location
    Giving error on :

    listFolders.Column(1, listFolders.ListCount - 1) = String(i, "-") & x.Name

    method or datamember not found...

  4. #4
    I can't seem to duplicate that error. It runs perfectly for me on Outlook 2000. What version of Outlook are you running?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •