Outlook macro return Runtime error : operation failed for mailbox

  • Thread starter Thread starter Shiv
  • Start date Start date
S

Shiv

I have a macro to process some mails in a mailbox, it worked fine all these
days(Though exceptionally slow).now it returns a Runtime error while setting
the mailitem to an object. Folder propeties return Operation failed. only
Inbox folder is accesible any folders within it return runtime errors.

Ex code:
Public Sub tester()
Dim objNS As Outlook.NameSpace
Dim objSubfolder As Outlook.MAPIFolder
Dim objItem As Outlook.MailItem

Set objNS = Application.GetNamespace("MAPI")
Set objRcpnt = objNS.CreateRecipient("(e-mail address removed)")
Set objSubfolder = objNS.GetSharedDefaultFolder(objRcpnt, olFolderInbox)
Set objSubfolder = objSubfolder.Folders.Item(11) '<== this is folder
called test which im uanable to acees only now...

Set objItem = objSubfolder.Items(11) '<== Runtime error Here <==

End Sub


Today, 2:41 AM
Sue Mosher - Outlook MVP
Re: Outllok macro return Runtime error : operation failed for mailbox folder

GetSharedDefaultFolder does not give you access to subfolders. To work with
subfolders in another mailbox, you must have the mailbox visible in the
Folder List as a secondary mailbox and then will need to walk down the folder
hierarchy starting with the mailbox root.


Also, do not assume that everything in a mail folder is a MailItem. Declare
objItem as Object and check the value of its Class property to find out what
kind of item it is.

@sue:
I have the mailbox shared in my OL 2007,the macro worked fine all these
days,now all my team has this problem.Also im new to VBA
Our Monthly reports depend on making it work.
Thanks
 
What happens if you use the folder name instead of its index (11)?

--
Best regards
Michael Bauer - MVP Outlook

: VBOffice Reporter for Data Analysis & Reporting
: Outlook Categories? Category Manager Is Your Tool
: <http://www.vboffice.net/product.html?pub=6&lang=en>



Am Mon, 29 Sep 2008 08:27:02 -0700 schrieb Shiv:
 
I suspect one of two things:
a) (Unlikely) There are not 11 items in the folder you are looking at so
..items(11) does not exist. But I guess you can see how many items there are
in the folder so you would have ruled this out.
b) (More likely) The Class of .items(11) is not olMail. It might look like
an e-mail but not be an Outlook.MailItem. You could test for this by using
something like this:

if not objSubfolder.Items(11).class = olmail then msgbox ("Not an Outlook
MailItem")

G
 
@Michael
The problem persists even with a folder ex: "test"
@GP
Yes .. the item may not be a mail item.. but the error is same even if it
is...

I use watch to see what is happen with the objects... i found all folders
within inbox return "Operation Failed " for all properties in the Object
Ex : ObjFolder => "Inbox"
Folders=>Item(1)=> "operation failed"
this is same for all the folders with in folders

I remeber very well when this code worked fine .. i could browse all the
properties
 
Back
Top