首页 > 解决方案 > Outlook 脚本不会保存附件

问题描述

下面的 Outlook 规则应该将来自 sender@bookstore.com 的带有礼品卡购买主题行的附件保存到磁盘,然后将电子邮件移动到“删除项目”文件夹,这样它就不会再次处理它。该规则在收到新电子邮件并将电子邮件移至“删除项目”文件夹但未保存附件时运行。

我怀疑该规则首先将邮件移动到“删除项目”文件夹,然后执行脚本以保存不再位于“收件箱”文件夹中的电子邮件附件。

我无法更改以下 Outlook 规则的顺序以先执行脚本然后移动邮件,但 Outlook 不允许。

有什么推荐吗?

Apply this rule after the message arrives
from sender@bookstore.com
 and with Gift Card Purchase in the subject
 and on this computer only
move it to the Deleted Items folder
 and run Project1.SaveAttachment
Public Sub SaveAttachment(MItem As Outlook.MailItem)
    Dim oAttachment As Outlook.Attachment
    Dim sSaveFolder As String
    sSaveFolder = "C:\Temp\"
    For Each oAttachment In MItem.Attachments
        oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
    Next
End Sub

标签: vbaoutlook

解决方案


在您的代码中使用MailItem.Delete 方法 (Outlook)

通过删除move it to the Deleted Items folder然后将以下内容添加到您的代码来更新您MItem.Delete的规则Next

例子

For Each oAttachment In MItem.Attachments
    oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next

MItem.Delete

推荐阅读