Become a Columnist Microsoft Exchange Site Microsoft Support SiteMSDN Exchange Site



Find a folder by Name

' Function to walk a path to open an Outlook folder
' Dim flr As Outlook.MAPIFolder
' Set flr = OpenMAPIFolder("\Microsoft Mail Shared Folders\SharedFolder\Contacts")

' This routine does the following generically:
' Set ns = app.GetNamespace("MAPI")
' Set flr = ns.Folders("Microsoft Mail Shared Folders")
' Set flr = flr.Folders("Shared Folder")
' Set flr = flr.Folders("Contacts")

Function OpenMAPIFolder(ByVal szPath As String) As Outlook.MAPIFolder

Dim app As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim flr As Outlook.MAPIFolder
Dim szDir As String
Dim i As Long

If Left(szPath, Len(Application.PathSeparator)) = Application.PathSeparator Then
szPath = Mid(szPath, Len(Application.PathSeparator) + 1)
Set flr = app.ActiveExplorer.CurrentFolder
End If

While szPath <> ""
i = InStr(szPath, Application.PathSeparator)

If i Then
szDir = Left(szPath, i - 1)
szPath = Mid(szPath, i + Len(Application.PathSeparator))
szDir = szPath
szPath = ""
End If

If flr Is Nothing Then
Set ns = app.GetNamespace("MAPI")
Set flr = ns.Folders(szDir)
Set flr = flr.Folders(szDir)
End If


Set OpenMAPIFolder = flr
End Function

Once you have the folder, you could save the EntryID, and use that to reopen the folder...

Disclaimer: Your use of the information contained in these pages is at your sole risk. All information on these pages is provided "as is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Stephen Bryant or Pro Exchange. OutlookExchange.Com, Stephen Bryant and Pro Exchange shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

Copyright Stephen Bryant 2008