I have upgraded Outlook to 2010 & have an error in my VBA code ... RRS feed

  • Question

  • 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 References you need to add ?!?) but I found a Blog by Brij Raj Singh 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.

    I wrote this years ago and it has always worked, but to be honest I haven't looked at VBA for years & I don't understand what a lot of the code is doing !!! Basically, if an E:Mail is from a specific Yahoo Group, in this case KA-Clough, I want that E:Mail moved to my Clough folder (there are loads of these Group & Folder options). One thing I have noticed today, is that the structure of my Outlook folders looks different to before & rather than everything being inside a folder called Gary, it now says Outlook(Gary) at the top, but if I amend the program to remove \Gary from everywhere it makes no difference, I get the same error.

    This is the code ...

    Case Is = ""
                Set MyDest = OpenMAPIFolder("\Gary\Kickabout\Clough")
                MyEMail.Move MyDest
                GoTo Next_EMail
    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) 
            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("\")) 
                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 
                Set flr = flr.Folders(szDir) 
            End If 
        Set OpenMAPIFolder = flr 
    End Function 

    This is the error ...

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

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

    Wednesday, September 19, 2012 3:07 PM


All replies

  • Hi Gary,

    Please have look at the sample posted on below mentioned article to modify your VBA code:



    Wednesday, September 19, 2012 4:28 PM
  • Brijs,

    I am getting the exact same error ... the data I pass to the Function is "\Kickabout\Clough".

    I have amended the code slightly to remove all leading backslashes, so when it hits the line ...

    Set TestFolder = Application.Session.Folders.Item(FoldersArray(0))

    ... FoldersArray(0) = "Kickabout", but this exits via GetFolder_Error, so I commented out the On Error line & reran, and I get the same message !!!

    Now I know that the example has "\\Mailbox - Dan Wilson" in front of the folder names, could this be the problem ? Do I need this exact wording & my user name ?!? 

    Thinking about it, I guess I need to find the exact path, but where do I find it ?!?

    Wednesday, September 19, 2012 6:29 PM
  • OK, no worries, I have found it, right click on the folder & Properties ... Thanks !

    Wednesday, September 19, 2012 6:32 PM