Attaching mail items in Outlook 2010

A

Alex K

The code below works with Outlook 2007, but fails with Outlook 2010 RTM. The
"objAttachments.Add" line throws the following error:
---------------------------
Run-time error '-2147221233 (8004010f)':

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


Any ideas on a workaround?


Sub AddAttachment()
Dim objItem As Outlook.MailItem
Dim objAttachments As Outlook.Attachments
Dim objItemAtt As Outlook.MailItem

Set objItem = Application.CreateItem(olMailItem)
Set objItemAtt = Application.ActiveExplorer.Selection.Item(1)
Set objAttachments = objItem.Attachments
objAttachments.Add objItemAtt, Outlook.olEmbeddeditem, 1, "foo"
objItem.Display
End Sub


Thank you in advance,
ak
 
K

Ken Slovak - [MVP - Outlook]

See if it works better calling that as a function, setting an Attachment
object as the return value.
 
A

Alex K

Do you mean like this:

Sub AddAttachment()
Dim objItem As Outlook.MailItem
Dim objAttachments As Outlook.Attachments
Dim objItemAtt As Outlook.MailItem
Dim objAtt As Outlook.Attachment

Set objItem = Application.CreateItem(olMailItem)
Set objItemAtt = Application.ActiveExplorer.Selection.Item(1)
Set objAttachments = objItem.Attachments
Set objAtt = objAttachments.Add(objItemAtt, Outlook.olEmbeddeditem, 1,
"foo")
objItem.Display
End Sub


Same exact result. What else can I try?

Thanks a lot for your help.
ak
 
K

Ken Slovak - [MVP - Outlook]

I verified that this doesn't work in Outlook 2010 RTM. I'll report it to the
product group.

As a workaround save the selected message as an MSG file, then attach the
MSG file. That seems to work.
 
K

Ken Slovak - [MVP - Outlook]

What is your configuration for testing? Are you using Exchange mailbox
accounts (if so are they cached or online), are you using PST files? What
OS's did you test on?
 
K

Ken Slovak - [MVP - Outlook]

In further testing both by me and by the Outlook product group, it appears
that the code will work in Outlook 2010 if you are using Exchange mailboxes,
not with PST files.

So the code can run as is with mailboxes, with a PST store provider you'd
need to use the workaround I provided.

I'll see if I can get this on a fix list for SP1, and get it documented.
 
C

Charlie Hall

Hi Ken,

Any resolution to this problem re SP1 or hotfix?

In a related issue, I would like to be able to programmatically remove attachments - your workaround does not help for that - any suggestions?

Thanks in advance
The code below works with Outlook 2007, but fails with Outlook 2010 RTM. The
"objAttachments.Add" line throws the following error:
---------------------------
Run-time error '-2147221233 (8004010f)':

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


Any ideas on a workaround?


Sub AddAttachment()
Dim objItem As Outlook.MailItem
Dim objAttachments As Outlook.Attachments
Dim objItemAtt As Outlook.MailItem

Set objItem = Application.CreateItem(olMailItem)
Set objItemAtt = Application.ActiveExplorer.Selection.Item(1)
Set objAttachments = objItem.Attachments
objAttachments.Add objItemAtt, Outlook.olEmbeddeditem, 1, "foo"
objItem.Display
End Sub


Thank you in advance,
ak
On Tuesday, May 04, 2010 8:55 AM Ken Slovak - [MVP - Outlook] wrote:
See if it works better calling that as a function, setting an Attachment
object as the return value.
Sub AddAttachment()
Dim objItem As Outlook.MailItem
Dim objAttachments As Outlook.Attachments
Dim objItemAtt As Outlook.MailItem
Dim objAtt As Outlook.Attachment

Set objItem = Application.CreateItem(olMailItem)
Set objItemAtt = Application.ActiveExplorer.Selection.Item(1)
Set objAttachments = objItem.Attachments
Set objAtt = objAttachments.Add(objItemAtt, Outlook.olEmbeddeditem, 1,
"foo")
objItem.Display
End Sub


Same exact result. What else can I try?

Thanks a lot for your help.
ak

"Ken Slovak - [MVP - Outlook]" wrote:
On Tuesday, May 04, 2010 5:44 PM Ken Slovak - [MVP - Outlook] wrote:
I verified that this does not work in Outlook 2010 RTM. I will report it to the
product group.

As a workaround save the selected message as an MSG file, then attach the
MSG file. That seems to work.
On Wednesday, May 05, 2010 2:49 PM Ken Slovak - [MVP - Outlook] wrote:
What is your configuration for testing? Are you using Exchange mailbox
accounts (if so are they cached or online), are you using PST files? What
OS's did you test on?
On Wednesday, May 05, 2010 3:35 PM Ken Slovak - [MVP - Outlook] wrote:
In further testing both by me and by the Outlook product group, it appears
that the code will work in Outlook 2010 if you are using Exchange mailboxes,
not with PST files.

So the code can run as is with mailboxes, with a PST store provider you would
need to use the workaround I provided.

I will see if I can get this on a fix list for SP1, and get it documented.
 
K

Ken Slovak

I haven't heard anything, but I don't know what's in SP1 or when it will be
released. As far as a hotfix, I haven't checked but you would need to open a
support case. When support determines your case is due to a bug you will not
be charged for the support case. If there's a business case made (or you
pay) for a hotfix, one can be created or supplied, if possible. I don't get
involved in that, that's an MS internal process.

I haven't seen any problems here in removing attachments. What problem are
you having with that? Do you have any repro code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top