?
Solved

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

Posted on 2004-11-18
4
Medium Priority
?
3,089 Views
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
      Next
    Next
  Next

  If strEntryID = "" Then
    MsgBox "lifeonline not found"
    Exit Sub
  Else
    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.



Alan
0
Comment
Question by:Alan Warren
3 Comments
 
LVL 26

Author Comment

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

Alan  ":0)
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 13042845
PAQed with points refunded (500)

modulo
Community Support Moderator
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 13306786
Hi,

@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,
Raisor
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

850 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