Alan Warren
asked on
Reference a sub-sub-folder in secondary PST using VBA
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(strEn tryID)
End If
End Sub
I was hoping I could do something as simple as:
Set olFolder = olNS.Folders("\\test\Inbox \lifeonlin e") ' 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
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")
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(strEn
End If
End Sub
I was hoping I could do something as simple as:
Set olFolder = olNS.Folders("\\test\Inbox
Had a bit of a look at the .Find method but I think it only applies to Items in current folder.
Alan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
@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
ASKER
Alan ":0)