我有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
答案 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