思路&方案:
Outlook规则功能检测是否有附件 + vba获取邮件中的附件并存储
-
1、开启数字证书(
更安全!
) -
路径:C:\Program Files (x86)\Microsoft Office\root\Office16
-
输入自己的字符串,点击确定即可,最好记录下来。
-
2、到注册表开启,规则中的运行脚本功能。
-
路径:计算机\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Outlook\Security
-
创建一个DWORD(32位)值,命名为
EnableUnsafeClientMailRules
并设置值为1 。 -
3、回到Outlook开启宏相关的设置
-
调出开发工具
-
开启脚本能在邮件文件夹中运行
-
4、编写VBA脚本
Sub SaveAttachment(ByVal Item As Object, path$, Optional condition$ = "*")
Dim olAtt As Attachment
Dim i As Integer
Set regEx = CreateObject("VBSCRIPT.REGEXP")
With regEx
.Global = True
.Pattern = "[\\:&\/\*\?""\<\>\|]|[^A-Za-z0-9\u4e00-\u9fa5]"
If Item.Attachments.Count > 0 Then
Pfloder = path & .Replace(Item.Subject, "_") & "\"
If Dir(Pfloder, vbDirectory) = "" Then MkDir Pfloder '若无文件夹则新建该文件夹
For Each att In Item.Attachments
If att.FileName Like condition Then
att.SaveAsFile Pfloder & att.FileName
End If
Next
End If
End With
Set olAtt = Nothing
End Sub
Sub 保存(Item As Outlook.MailItem)
'Debug.Print "有邮件"
'MsgBox "有邮件"
SaveAttachment Item, "C:\Mails\"
End Sub
-
添加一下第一步设置的数字签名
-
5、设置规则即可~