If you are running this code in Outlook, you should not be using

CreateObject("Outlook.Application")

Use the native Application Object to derive all your other objects. i.e. Set objOL = Application.

What line is the code stopping on, and what mailitem is being processed? Are you sure that mailitem contains attachments?


FYI you might also want to fix this code:

[vba]Set objAttachments = objSelection(i).Attachments
For j = 1 to objSelection(i).Attachments.Count[/vba]
objAttachments is already a reference to the attachments collection, so you probably meant

[vba]Set objAttachments = objSelection(i).Attachments
For j = 1 to objAttachments.Count[/vba]
--JP

Quote Originally Posted by Agni1978
Error running code on share mail box
Hi,

I am using the below code to print the attachments of selected e-mails on any folder in outlook. But when I am running this on a local Inbox folder this code is working pretty much in the expected manner, But unfortunately my requirement is to select the mails in a Shared Mailbox and print the attachments. I am experiencing error
Run-time error '-21477221233 (8004010f)': Method 'Attachments' of object 'MailItem' failed.

The same was happening for me when I am using code in KB522 on shared mailbox with some modification. Refthread KB522 RuntimeError in TargetFolderItems_ItemAdd )

Can you please let me know what to change in code in order to get the below code work for Shared Mail box?

Thanks in advance