Saving Outlook Attachments - but not the inline images
Hi Guys,
Looking for some assistance in avoiding saving inline images (images which show in an email as opposed to those which are attached).
I am using the following code for saving the attachments to an email and it works fine - but includes ALL attachments, including inline images. How can I avoid that?
Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem, strFolderPath As String) Dim oAttachment As Outlook.attachment Dim sSaveFolder As String Dim fso As New Scripting.FileSystemObject Dim bName As String Dim sSaveFolder As String 'Checking that path ends in \ If Right(strFolderPath, 1) = "\" Then ' fall through Else: strFolderPath = strFolderPath & "\" End If sSaveFolder = strFolderPath For Each oAttachment In MItem.Attachments ' change the file name with the index 'Debug.Print "DisplayName: " & oAttachment.DisplayName 'Debug.Print "FileName: " & oAttachment.FileName 'Debug.Print "Pathname: " & oAttachment.PathName ' get the filename (no extension) bName = fso.GetBaseName(oAttachment.DisplayName) ' rename the file with no extension using the index as the order ' to be merged at a future date bName = oAttachment.Index & "-" & bName ' put the extension back on bName = bName & "." & fso.GetExtensionName(oAttachment.DisplayName) ' save the file with the new name oAttachment.SaveAsFile sSaveFolder & bName NextEnd Sub
Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem, strFolderPath As String) Dim oAttachment As Outlook.attachment Dim sSaveFolder As String Dim fso As New Scripting.FileSystemObject Dim bName As String Dim sSaveFolder As String 'Checking that path ends in \ If Right(strFolderPath, 1) = "\" Then ' fall through Else: strFolderPath = strFolderPath & "\" End If sSaveFolder = strFolderPath For Each oAttachment In MItem.Attachments If oAttachment.Type <> olEmbeddeditem Then ' change the file name with the index 'Debug.Print "DisplayName: " & oAttachment.DisplayName 'Debug.Print "FileName: " & oAttachment.FileName 'Debug.Print "Pathname: " & oAttachment.PathName ' get the filename (no extension) bName = fso.GetBaseName(oAttachment.DisplayName) ' rename the file with no extension using the index as the order ' to be merged at a future date bName = oAttachment.Index & "-" & bName ' put the extension back on bName = bName & "." & fso.GetExtensionName(oAttachment.DisplayName) ' save the file with the new name oAttachment.SaveAsFile sSaveFolder & bName End If NextEnd Sub
Hi Bill ... thanks for the help so far ... can you explain to me the difference between the two coded solutions you have provided ... ie oAttachment.Fields(&H3712001E) = "" and oAttachment.Type <> olEmbeddeditem ...
MTIA
DWE
dwe0608
ASKER
Hi Alexei ... thanks for the input ... how would you incorporate your suggestion into the code ... currently I am using a small function which is working to an extent ...
Public Function IsHiddenAttachment(olkAtt As Outlook.attachment) As Boolean ' Purpose: Determines if an attachment is a hidden attachment. 'Const PR_ATTACH_CONTENT_ID = "http://schemas.microsoft.com/mapi/proptag/0x3712001E" - original Const PR_ATTACH_CONTENT_ID = "http://schemas.microsoft.com/mapi/proptag/0x7FFE000B" - altered Dim olkPA As Outlook.PropertyAccessor, varTemp As Variant On Error Resume Next Set olkPA = olkAtt.PropertyAccessor varTemp = olkPA.GetProperty(PR_ATTACH_CONTENT_ID) IsHiddenAttachment = (Trim(varTemp) <> "") 'Debug.Print varTemp On Error GoTo 0 Set olkPA = NothingEnd Function
Thanks guys, a combination of suggestions worked ...:-)
jalimocho o
Dear dwe0608, In case you were able to make it work, would you mind sharing the code? I'm also facing a similar problem. I want to count the number of attachments in an email excluding the inline ones, but every hint I find in internet seems to work fine in older versions of Outlook but not in Outlook 2016.
Open in new window
»bp