Udostępnij za pośrednictwem


FYI: BUG: Attachments.Add fails for POP3/IMAP only accounts when the attachment type is Outlook.olEmbeddedItem

Problem: Attachments.Add fails only for POP3/IMAP accounts when the attachment type is Outlook.olEmbeddedItem

Cause: This is a known issue with Microsoft Product (Outlook 2010) and we have an internal fix available. The fix is expected to go public with the release of next Service Pack for the product.

Repro Code:

1. Setup a POP3 only profile
2. Make sure that there is at least one mail item in the Inbox.
3. Make the Inbox the current folder and run the following code:

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

Actual Result:

objAttachments.Add raises an error:

Run-time error '-2147221233 (8004010f)':
The attempted operation failed. An object could not be found.

Expected Result:  

No error

Workaround:

There is a workaround by saving the embedded item to the file system, similar to the following:

Sub TestAddAttachmentWorkaround()
    Dim objItem As Outlook.MailItem
    Dim objAttachments As Outlook.Attachments
    Dim objItemAtt As Outlook.MailItem
    Dim strPath As String
   
    Set objItem = Application.CreateItem(olMailItem)
    objItem.Subject = "TestAddAttachment"
    Set objItemAtt = Application.ActiveExplorer.Selection.Item(1)
    strPath = Environ("TEMP") & "\testmsg.msg"
    objItemAtt.SaveAs strPath, olMSG
    Set objAttachments = objItem.Attachments
    objAttachments.Add strPath, Outlook.olEmbeddeditem, 1, objItemAtt.Subject
    objItem.Display
    Kill strPath
End Sub

Please contact Microsoft PSS if you are affected by this problem and cannot wait until next service pack release of Outlook 2010.

Comments