Reference a sub-sub-folder in secondary PST using VBA

Posted on 2004-11-18
Last Modified: 2008-01-09
Hello Outlook experts,

I use the following code in Ms Access 2000 to find a sub-sub-folder in an added PST catalog, it works, but I was wondering if there might be a more efficient way to do this.

Option Explicit

Dim olApp As Outlook.Application

Public Sub GetMail()
' Reference: Microsoft Outlook Object Library
  Dim olNS As NameSpace
  Dim olFolder As MAPIFolder
  Set olApp = New Outlook.Application
  Set olNS = olApp.GetNamespace("MAPI")  ' open the MAPI Namespace
  Dim fol As MAPIFolder
  Dim subFolder As MAPIFolder
  Dim subsubfolder As MAPIFolder
  Dim strEntryID As String
  For Each fol In olNS.Folders
    Debug.Print fol.Name, fol.FolderPath
    For Each subFolder In fol.Folders
      Debug.Print "  -" & subFolder.Name, subFolder.FolderPath, subFolder.EntryID
      If subFolder.FolderPath = "\\test\Inbox\lifeonline" Then: strEntryID = subFolder.EntryID
      For Each subsubfolder In subFolder.Folders
        If subsubfolder.FolderPath = "\\test\Inbox\lifeonline" Then: strEntryID = subsubfolder.EntryID
        Debug.Print "    -" & subsubfolder.Name, subsubfolder.FolderPath, subsubfolder.EntryID

  If strEntryID = "" Then
    MsgBox "lifeonline not found"
    Exit Sub
    Set olFolder = olNS.GetFolderFromID(strEntryID)
  End If

End Sub

I was hoping I could do something as simple as:
    Set olFolder = olNS.Folders("\\test\Inbox\lifeonline")  ' error: the operation failed an object could not be found

Had a bit of a look at the .Find method but I think it only applies to Items in current folder.

Question by:Alan Warren
    LVL 26

    Author Comment

    by:Alan Warren
    Set olFolder = olNS.Folders.Item("test").Folders.Item("Inbox").Folders.Item("lifeonline")

    Alan  ":0)

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator
    LVL 15

    Expert Comment


    @alanwarren ... however ... your little peace of code was a great help to me in some kind of a same situation ... the level where Outlook Folder / Item & Items access can get down to has really astonished me ... but there are huge ways of usage ... thanks alanwarren!

    Best regards,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Use email signature images to promote corporate certifications and industry awards.
    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.
    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 …
    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…

    760 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

    7 Experts available now in Live!

    Get 1:1 Help Now