如何自动下载邮件附件到指定文件夹

2020-10-20  本文已影响0人  九月_1012
  1. 首先确认outlook 2016 user权限
  1. 使outlook 2016有“run a script”选项
  1. 在outlook邮箱插入VBA脚本
    点击“Alt + F11”,双击界面编辑框,插入如下代码
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

Public Sub SaveAttach(MyItem As Outlook.MailItem)
    SaveAttachment MyItem, "C:\Data\MailAttached\"
    'MsgBox "附件已保存"
End Sub

Private Sub SaveAttachment(ByVal Item As Outlook.MailItem, path, Optional condition = "*")
    Dim olAtt As Outlook.Attachment
    Dim i As Integer
    If Item.Attachments.Count > 0 Then
        For i = 1 To Item.Attachments.Count
            Set olAtt = Item.Attachments(i)
            If olAtt.FileName Like condition Then
                olAtt.SaveAsFile path & olAtt.FileName
            End If
        Next
    End If
    Set olAtt = Nothing
    Sleep 100
End Sub

Private Sub UserForm_Click()

End Sub
  1. 创建下载的规则
    注意点击“run a script”,选择刚才的脚本


    image.png
上一篇 下一篇

猜你喜欢

热点阅读