打开Outlook - Option - Trust Center - Truster Center Settings - Macro Settings - 勾选Enable all macros。
打开Outlook - Option - Trust Center - Truster Center Settings - Email Security - 勾选Allow script in shared folders 和 All script in public folders
重点:重启Outlook
编写宏程序,按下Alt+F11,创建新项目,把程序copy进去,文件夹地址改一下
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Public Sub SaveAttach(MyItem As Outlook.MailItem)
SaveAttachment MyItem, "C:\Data\MailAttached\" ,"*.xlsx"
'MsgBox "附件已保存"
End Sub
Private Sub SaveAttachment(ByVal Item As Outlook.MailItem, path, Optional condition = "*")
Dim olAtt As Outlook.Attachment
Dim i As Integer
Dim dateFormat
dateFormat = Format(Now, "yyyy-mm-dd hh-mm-ss")
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 & dateFormat & "_" & olAtt.FileName
End If
Next
End If
Set olAtt = Nothing
Sleep 1000
End Sub
第三步:
制作运行规则
打开注册表编辑器regedit,在路径HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security下增加一个DWORD值型的EnableUnsafeClientMailRules项,设置值为1