VBA Outlook,保存电子邮件附件,但不保存电子邮件正文中的图像

时间:2020-09-22 12:54:24

标签: vba outlook

我收到一封电子邮件,在电子邮件正文中有两个图像作为签名的一部分,在附件中有两个文件。

enter image description here

如何仅将两个文件保存在附件中(绿色箭头),而忽略电子邮件正文中的其他两个文件(红色箭头)。 就像Outlook这个选项本身一样:

enter image description here

不幸的是,不能检查附件是.gif还是.png或.jpg。我们确实收到了要保存的这类文件作为附件。

提前感谢您的支持!

这是我使用的代码。但是它也可以保存电子邮件正文中的(图像)文件。

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

0 个答案:

没有答案