自动保存Outlook邮件的附件

outlook 在工作中定期或不定期会收到一些数据文件,然后要将它们的附件保存到自己的电脑上,下面演示如何让Outlook自动做这件事情。

首先,下面的SaveAttach函数可以保存附件中的docx文档到D盘根目录下。用ALT+F11打开VBA编辑器,插入下述代码:


Public Sub SaveAttach(Item As Outlook.MailItem)
    SaveAttachment Item, "D:\", "*.docx"
    ' MsgBox "附件已保存"
End Sub

' 保存附件
' path为保存路径,condition为附件名匹配条件
Private Sub SaveAttachment(ByVal Item As Object, path$, Optional condition$ = "*")
    Dim olAtt As Attachment
    Dim i As Integer

    If Item.Attachments.Count > 0 Then
        For i = 1 To Item.Attachments.Count
            Set olAtt = Item.Attachments(i)
            ' save the attachment
            If olAtt.FileName Like condition Then
                olAtt.SaveAsFile path & olAtt.FileName
            End If
        Next
    End If
    Set olAtt = Nothing
End Sub

如何实现自动保存呢?利用Office Outlook 2007的规则,它可以设定对满足一定条件的邮件自动运行脚本,然后选择脚本为SaveAttach函数即可。这样便能实现收到某些邮件时自动保存符合条件的附件到相应文件目录。

标签:

东明猜你会喜欢· · · · · ·

我要发表评论 »