保存特定附件文件类型

时间:2018-01-04 05:29:07

标签: vba outlook outlook-vba

我有VBA代码自动下载(保存)收到的邮件附件。

我需要制定条件才能下载(保存).xlsx.jpg个文件。

 Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
 Dim oAttachment As Outlook.Attachment
 Dim sSaveFolder As String
 sSaveFolder = "C:\Users\DT168\Documents\outlook-attachments\"
 For Each oAttachment In MItem.Attachments
     oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
 Next
 End Sub

1 个答案:

答案 0 :(得分:0)

Simply use Select Case Statement

Dim FileType As String

For Each oAttachment In MItem.Attachments
    FileType = LCase$(Right$(oAttachment.FileName, 4)) ' Last 4 
          Select Case FileType
           Case "xlsx", ".jpg"
          oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName 
        End Select
    Next