On Outlook 2007 or previous version for the Outlook we can refer to the public folder as below:
Set olns =Item. Application.GetNamespace("MAPI")
Set pub = olns.Folders("Public Folders")
However, the above given code snippet would fail on Outlook 2010 by throwing exception "Run-time error -2147221233 (8004010f) The attempted operation failed. An object could not be found" because with Outlook 2010.
We have an option to configure multiple exchange account in the same profile and Outlook appends the user's SMTP address used to configure the account to the mailbox/public folder store name to identify each of the account and Outlook would show/refer to the mailbox/public folder as shown in image below.
Here is the sample code snippet in VBA to get reference to Public Folder Store using Outlook Object Model for Outlook 2010:
'NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose.
'This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment.
If InStr(Item.Application.Version, "14") Then
Set accs = olns.Accounts
For Each Account In accs
If Account.AccountType = olExchange And Account.SmtpAddress = olns.Session.DefaultStore Then
Set pub = olns.Folders("Public Folders" & " - " & Account.SmtpAddress)
MsgBox "Got the Pub folders"
If pub Is Nothing Then
MsgBox "No Public Folder store found for the default exchange mailbox"
Hope this helps!!! Feel free to ask questions related to Outlook/Exchange development.
Hi and Thanks - have been searching for info on this all day.
I need to address named public folders (from variables) in Access vba in order to create public tasks. We are Office 2010 now and Exchange under SBS 2008.
I previously used the code below, which saw the same error as you report above.
I guess I need to combine your snippet above.
I get that I need to adress the Public Folder by my Account.SMTPAddress but wonder how I navigate down to a specific folder within the Public Store.
Old 2007 Code ====
Dim ObjAPP As Outlook.Application
Dm objSystem_TaskFolder As Outlook.MAPIFolder
Dim objNewTask As Outlook.TaskItem
Set ObjAPP = CreateObject("Outlook.Application")
Set objNS = ObjAPP.GetNamespace("MAPI")
Set objSystem_TaskFolder = _
Set objNewTask = _
@Glenn we just need to use logic given in the article to get reference to the top level node of the public folder store and rest of the your code looks good.
So replace the below line of the code with the logic explained in the post
objNS.Folders.Item(g_Public_Folders). to get refer to the public folder store and then use it as:
Below are segments of my code for an Outlook Form for time off request. I need to adapt this for Outlook 2010; can someone please show me the way?
Thanks in advance!
'-----This section is toward the top of my code----
' set user options
'public Time Off folder name and path
mstrVacFolder = "Public Folders/All Public Folders/Time Off"
Set objApp = Application
Set objNS = objApp.GetNamespace("MAPI")
arrName = Split(strName, "/")
Set objFolders = objNS.Folders
blnFound = False
For I = 0 To UBound(arrName)
For Each objFolder In objFolders
If objFolder.name = arrName(I) Then
Set objFolders = objFolder.Folders
blnFound = True
blnFound = False
If blnFound = False Then
If blnFound = True Then
Set GetMAPIFolder = objFolder
Set GetMAPIFolder = Nothing
Set objApp = Nothing
Set objNS = Nothing
Set objFolder = Nothing
Set objFolders = Nothing
Set objExpl = Nothing
' from Randy Byrne, Building Applications with Outlook 2000
On Error Resume Next
strFolderPath = "\" & objFolder.name
Set objChild = objFolder
Do Until Err <> 0
Set objParent = objChild.Parent
If Err <> 0 Then
strFolderPath = "\" & objParent.name & strFolderPath
Set objChild = objParent
GetFolderPath = strFolderPath
Set objChild = Nothing
Set objParent = Nothing
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olFolderCalendar)
mstrVacFolderViewName = objFolder.CurrentView
GetCalFolder = GetFolderPath(objFolder)
DO you happen to have the full code snippet for access to fucntion. Where can i get documentation on the library.
I use this :
strFolder = appOutlook.Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Parent
This will return the correct public folder. No need to verify Outlook version or concatenate user to folder name.
Great post, thank you. I'd been having trouble with this.
My solution to the long folder paths was to just drop the folders that I care about in the Favorites for the Public Folders.
Great info - thanks everyone. You have helped me convert old VB script to Outlook 2010 VBA