Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Saving Outlook Attachments - but not the inline images

Avatar of dwe0608
dwe0608Flag for Australia asked on
Microsoft OfficeOutlookVBA
8 Comments1 Solution258 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
    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
    Next
    
End Sub

Many thanks

DWE
ASKER CERTIFIED SOLUTION
Avatar of Alexei Kuznetsov
Alexei KuznetsovFlag of United States of America imageMicrosoft Outlook MVP

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

Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answers