'Saving "Device Independent Bitmap" attachment
How to properly save this kind of attachment (from signed message)? I saved this with .SaveAsFile method, but it is without any extension and no application can open it.
Set OutItem = Application.ActiveExplorer.Selection.Item(1)
For Each att In OutItem.Attachments
att.SaveAsFile "C:\Temp\" & att.DisplayName
Next
Solution 1:[1]
For the olOlE attachments, you would need to open the attachment as an IStorage COM object and extract the data (which can be mangled) from one of the streams inside the storage - you can see the data in OutlookSpy (I am its author): select the message, click IMessage button on the OutlookSpy ribbon, go to the GetAttachmentTable tab, double click on one of the attachments. Select the PR_ATTACH_DATA_OBJ property, right click, IMAPIProp::OpenProperty, select IID_IStorage. The data cannot be accessed in VBA using the Outlook Object Model
If using Redemption is an option (I am also its author), its RDOAttachment.SaveAsFile
method is smart enough to extract BMP, EMF, PDF, Excel, etc. file data from the storage. Something like the following (off the top of my head) should do the job:
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set rMsg = Session.GetRDOObjectFromOutlookObject(Application.ActiveExplorer.Selection.Item(1))
For Each att In rMsg.Attachments
att.SaveAsFile "C:\Temp\" & att.FileName
Next
Solution 2:[2]
The DisplayName property of the Attachment class returns a string representing the name, which does not need to be the actual file name, displayed below the icon representing the embedded attachment.
Try to use the FileName property which returns a String representing the file name of the attachment.
Also you may specify the file extension on the code explicitly, for example:
For Each att In OutItem.Attachments
att.SaveAsFile "C:\Temp\" & att.DisplayName & ".docx"
Next
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Eugene Astafiev |