我需要VBA编码方面的帮助,以查看是否可以从Outlook电子邮件中下载电子邮件附件并将其保存在PC的不同文件夹中。

时间:2019-01-08 11:35:37

标签: vba outlook outlook-vba

我已经设置了将电子邮件附件下载到我的PC的代码。 但现在我陷入了要在PC上不同位置下载特定电子邮件附件的问题

1 个答案:

答案 0 :(得分:0)

这应该使您入门。将其放在Outlook中的模块中。您将需要更改文件夹信息等。

Public Sub SaveAttachmentsToDisk()

    Dim currentExplorer As Explorer
    Dim currentSelection As Selection
    Dim ndxItem As Outlook.MailItem
    Dim attachFile As Outlook.Attachment

    Const SaveFolder As String = "C:\OutlookAttachments\"

    Set currentExplorer = Application.ActiveExplorer
    Set currentSelection = currentExplorer.Selection

    If currentSelection.Count <= 0 Then Exit Sub
    If TypeName(currentSelection.Item(1)) <> "MailItem" Then Exit Sub

    For Each ndxItem In currentSelection
        Debug.Print ndxItem.Body
        For Each attachFile In ndxItem.Attachments
            If VBA.Right$(attachFile.DisplayName, 3) <> "jpg" And VBA.Right$(attachFile.DisplayName, 3) <> "png" Then
                attachFile.SaveAsFile SaveFolder & attachFile.FileName
            End If
        Next attachFile
    Next ndxItem

End Sub
相关问题