Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Outlook VBA
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."
Posted 18-Sep-12 9:11am
Comments
Richard MacCutchan at 18-Sep-12 16:05pm
   
You need to run this through the VBA debugger and find out which line of code causes the error. That should help identify what is going wrong.
Gary Heath at 18-Sep-12 16:46pm
   
The error occurs on the line where I have written "<<< The Error occurs on this line" !!!
Richard MacCutchan at 18-Sep-12 16:50pm
   
So you need to check the value of ns and szDir to see if they are valid or not.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You may want to run SCANPST first
  Permalink  
Comments
Gary Heath at 18-Sep-12 18:24pm
   
Whilst I appreciate that you are trying to help, I do not understand why this would help ... it's a fully working program (in Outlook 2007) on a perfectly working E:Mail system (with no problems) ... however, I did it and it made no difference ...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This code works in Outlook 2010 ...
 
http://msdn.microsoft.com/en-us/library/office/ff868990.aspx[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 390
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 19 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100