getrighteous
Programmer
I am trying to write a VBA script in Excel that will allow me to access other spreadsheets that have been posted to a Public Folder in Exchange. I have researched this for a long time, tried some code samples, but nothing seems to work.
Here is where I am at currently:
But objNS is getting set to nothing. Am I missing something? Is there a more elegant solution?
Thanks!
Here is where I am at currently:
Code:
Dim objNS As Outlook.Namespace
Dim colFolders As Outlook.Folders
Dim objFolder As Outlook.MAPIFolder
Dim arrFolders() As String
Dim I As Long
On Error Resume Next
strFolderPath = "Public Folders\All Public Folders\company\testfolder"
arrFolders() = Split(strFolderPath, "\")
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.Folders.Item(arrFolders(0))
If Not objFolder Is Nothing Then
For I = 1 To UBound(arrFolders)
Set colFolders = objFolder.Folders
Set objFolder = Nothing
Set objFolder = colFolders.Item(arrFolders(I))
If objFolder Is Nothing Then
MsgBox ("Empty")
Exit For
Else
MsgBox (I)
End If
Next
End If
Set GetFolder = objFolder
Set colFolders = Nothing
Set objNS = Nothing
Set objApp = Nothing
But objNS is getting set to nothing. Am I missing something? Is there a more elegant solution?
Thanks!