Scripting

如何使用新名稱將 Outlook 附件保存在驅動器中並在已存在的情況下覆蓋?

  • October 6, 2020

我正在使用下面的 VBA 腳本從電子郵件中下載附件並將其保存到我的 windows 目錄中。我需要幫助來修改此腳本 - 1) 在保存之前保存重命名附件 2) 如果文件已經存在,則覆蓋該文件。請幫忙。

Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "F:\RBL Attachments\"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim obj As Outlook.Attachment
Dim saveFolder As String
saveFolder = "D:\EmailAttachments"
    For Each obj In itm.Attachments
         obj.SaveAsFile saveFolder & "\" & obj.DisplayName
         Set obj = Nothing
    Next
End Sub

引用自:https://dba.stackexchange.com/questions/276606