troubleshooting Question

Saving Outlook Attachments - but not the inline images

Avatar of dwe0608
dwe0608Flag for Australia asked on
Microsoft OfficeOutlookVBA
8 Comments3 Solutions259 ViewsLast Modified:
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
        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
End Sub

Many thanks

Alexei Kuznetsov
Microsoft Outlook MVP

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros