I'm trying to get access to our public folder using vba in Outlook. Our system is connected to an exchange server. The public folder is outside of my account. So for example when i open outlook i have my mail box called "x Personal Email" and on the same level there is a folder called "Public Folders" so its not in my personal email but at the same level. The public folder is a company wide public folder that everyone has access to. I goal is to write a tool that reads this a particular sub-folder specific to my project and process the undeliverable emails.
Here is my code:
Set objApp = New Outlook.Application
Set objNameSpace = objApp.GetNamespace(Type:="MAPI")
Set objMAPIFolder = _
.Folders("Public Folders") _
.Folders("All Public Folders").Folders("Company").Folders("Undeliverable Letters")
For Each objMailItem In objMAPIFolder.Items
' Uncomment the next line if you want to verify results.
' Debug.Print objMailItem.SentOn & vbTab & _
If objMailItem.SentOn < Date Then
lngOldMailCounter = lngOldMailCounter + 1
lngNewMailCounter = lngNewMailCounter + 1
But i fail right when i step over objMAPIFolder .
I'm sure i'm doing something wrong but can anyone guide me in fixing this problem.