Outlook脚本无法保存附件

时间:2018-12-04 01:29:25

标签: vba outlook outlook-vba

下面的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

1 个答案:

答案 0 :(得分:0)

在您的代码中使用MailItem.Delete Method (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