0

I receive an email with two images in the email body as part of the signature and two files in the attachment.

enter image description here

How do I just save the two files in the attachment (green arrows) and ignore the other two files in the email body (the red arrows). Like this option of Outlook itself does:

enter image description here

Checking if the attachment is .gif or .png or .jpg is unfortunately not an option. We do receive these type of files as attachment we want to save.

Thanks in advance for the support!

This is the code I use. But it saves also the (image)files from the email body.

Sub SaveAttachments()
    Dim myOlApp As Outlook.Application
    Dim myInspector As Outlook.Inspector
    Dim myItem As Outlook.mailItem
    Dim myAttachments As Outlook.Attachments
    Set myOlApp = CreateObject("Outlook.Application")
    Set myInspector = myOlApp.ActiveInspector
    If Not TypeName(myInspector) = "Nothing" Then
        If TypeName(myInspector.CurrentItem) = "MailItem" Then
            Set myItem = myInspector.CurrentItem
            Set myAttachments = myItem.Attachments
            
            'Prompt the user for confirmation
            Dim strPrompt As String
            strPrompt = "Do you want to save the attachments..."
            If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
                For Each att In myAttachments
                    '[saving the attachment]
                                                
                Next att
                
                MsgBox "Attachments are saved"

            End If
            Set myAttachments = Nothing
            Set myItem = Nothing
        Else
            MsgBox "Only email attachments can be saved."
        End If

        Set myInspector = Nothing
    End If
    Set myOlApp = Nothing
End Sub
klingu
  • 559
  • 1
  • 7
  • 19
  • 1
    Possible duplicate of [Distinguish visible and invisible attachments with Outlook VBA](https://stackoverflow.com/questions/12310925/distinguish-visible-and-invisible-attachments-with-outlook-vba) – niton Sep 22 '20 at 18:28
  • @niton Thanks for pointing out to this Post! I saw a lot of Posts saving the Attachment(s) by many reasons and issues. But this Post wasn't shown to me till now! Works like a charm! – klingu Sep 24 '20 at 11:25

0 Answers0