我已为Outlook保存附件VBA代码。如果我收到具有相同名称的附件,则不会处理。如何覆盖并保存最新的?
Sub ExportAttach(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "C:\Users\Redirection\johndoe\Desktop\TestFolder"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub
答案 0 :(得分:2)
一种方法是:首先构造目标文件名,检查文件是否存在,如果是,则删除文件,然后保存文件。
Dim FN as String
FN = SaveFolder & "\" & objAtt.DisplayName
if (Dir$(fn) <> "") then kill fn ' delete if file exists
objAtt.saveAsFile fn