borg48
asked on
Problem accessing public folder via vba
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 = _
objNameSpace.GetDefaultFol der(Folder Type:=olPu blicFolder sAllPublic Folders) _
.Folders("Public Folders") _
.Folders("All Public Folders").Folders("Company ").Folders ("Undelive rable Letters")
For Each objMailItem In objMAPIFolder.Items
' Uncomment the next line if you want to verify results.
' Debug.Print objMailItem.SentOn & vbTab & _
objMailItem.Subject
If objMailItem.SentOn < Date Then
lngOldMailCounter = lngOldMailCounter + 1
Else
lngNewMailCounter = lngNewMailCounter + 1
End If
Next objMailItem
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.
THanks
Here is my code:
Set objApp = New Outlook.Application
Set objNameSpace = objApp.GetNamespace(Type:=
Set objMAPIFolder = _
objNameSpace.GetDefaultFol
.Folders("Public Folders") _
.Folders("All Public Folders").Folders("Company
For Each objMailItem In objMAPIFolder.Items
' Uncomment the next line if you want to verify results.
' Debug.Print objMailItem.SentOn & vbTab & _
objMailItem.Subject
If objMailItem.SentOn < Date Then
lngOldMailCounter = lngOldMailCounter + 1
Else
lngNewMailCounter = lngNewMailCounter + 1
End If
Next objMailItem
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.
THanks
what is the exact error message?
ASKER
Could not complete the operation. One or more parameter values are not valid.
But if i just put the first folder "Public Folders" i get the same error. So i think its the root folder that i'm not getting correct.
But if i just put the first folder "Public Folders" i get the same error. So i think its the root folder that i'm not getting correct.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.