PDA

View Full Version : Solved: Upgraded from Outlook 2007 to 2010 & am getting an error



vodkasoda
09-18-2012, 10:18 AM
Hi there, I have a small program that checks my E:Mails & moves them to specific folders, but after an upgrade to Outlook 2010 it no longer works. I thought I probably needed to add a Reference (how do you tell which one ?!?) but I found a Blog suggesting that this may be due to a change in the way Outlook 2010 works. I am not an expert in VBA by any means, so if somebody could help I would appreciate it immensely.

This is the code ...

Function OpenMAPIFolder(szPath)

'Pass a parameter to this module, in the following format, to set the rightmost Folder
'as the object, or live, Folder ... "\Gary\Kickabout\Attachments"

Dim app, ns, flr, szDir, i
Set flr = Nothing
Set app = CreateObject("Outlook.Application")
If Left(szPath, Len("\")) = "\" Then
szPath = Mid(szPath, Len("\") + 1)
Else
Set flr = app.ActiveExplorer.CurrentFolder
End If
While szPath <> ""
i = InStr(szPath, "\")
If i Then
szDir = Left(szPath, i - 1)
szPath = Mid(szPath, i + Len("\"))
Else
szDir = szPath
szPath = ""
End If
If IsNothing(flr) Then
Set ns = app.GetNamespace("MAPI")
Set flr = ns.Folders(szDir) <<< The Error occurs on this line
Else
Set flr = flr.Folders(szDir)
End If
Wend
Set OpenMAPIFolder = flr
End Function

... and this is the Error ...


Run Time Error '-2147221233 (8004010f)':

The attempted operation failed. An object could not be found.

vodkasoda
09-19-2012, 02:16 PM
This explains how to do it in Outlook 2010 if anybody gets the same problem ...

http://msdn.microsoft.com/en-us/library/office/ff868990.aspx