Discussion:
MAPIFolder/ActiveX Excel cannot find Outlook folder
(too old to reply)
Andy
2011-07-05 15:51:32 UTC
Permalink
Hi all,

I'm having a rather annoying issue after some users have been updated
to Office 2007 (from 2003)

Their issue is with the below code, which seems to cause errors
whether they already have Outlook open or not.

The code below is from Excel, and uses Outlook to find the path to a
certain public folder. It seems to be causing a "ActiveX component
can't create object" issue. Using Resume Next it seems to work on most
PC's but not all...
It seems to fail on the Getfolder function because it can't find
Outlook.

All references are correct, no missing ones.

Dim oOL As Outlook.Application

On Error Resume Next
Set oOL = GetObject("", "Outlook.Application")
If Err.Number = 429 Then
Err.Clear
Set oOL = New Outlook.Application
End If

Set oFolder = GetFolder("Public Folders\All Public Folders
\Guidance")

etc....

Public Function GetFolder(strFolderPath As String) As MAPIFolder

Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim colFolders As Outlook.Folders
Dim oFolder As Outlook.MAPIFolder
Dim arrFolders() As String
Dim i As Long
On Error Resume Next

strFolderPath = Replace(strFolderPath, "/", "\")
arrFolders() = Split(strFolderPath, "\")
Set objApp = Outlook.Application
Set objNS = objApp.GetNamespace("MAPI")
Set oFolder = objNS.Folders.Item(arrFolders(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(arrFolders)
Set colFolders = oFolder.Folders
Set oFolder = Nothing
Set oFolder = colFolders.Item(arrFolders(i))
If oFolder Is Nothing Then
Exit For
End If
Next
End If

Set GetFolder = oFolder
Set colFolders = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Function
Andy
2011-07-06 12:22:42 UTC
Permalink
I used some simpler code to see if Excel can find Outlook but still no
luck...

"Microsoft Outlook 12.0 Object Library" reference is ticked.

Sub OutlookTest()

On Error Resume Next
gOutlookApplication = GetObject(, "outlook.application")
If gOutlookApplication Is Nothing Then
Err.Clear
gOutlookApplication = CreateObject("Outlook.application")
End If
If gOutlookApplication Is Nothing Then
MsgBox ("Failed to connect" & _
vbCrLf & "error: " & Err.Description)
End If

End Sub

Any ideas?

Loading...