【发布时间】:2019-07-16 21:25:06
【问题描述】:
我需要对我收到的一些特定邮件使用规则。 我必须将附件保存到特定文件夹 I.E. D:\TEST) 然后将邮件移动到附加到 Outlook 的 ANOTHER FILE 邮箱文件中的特定子文件夹。
我找到并调整了代码以满足我的需要,但 Outlook 规则“麻木”,无法更改规则步骤执行的顺序:
如果消息命中规则:
将 MSG 移动到特定文件夹
然后运行脚本
所以总而言之,脚本没有找到 MSG,因为它是按规则移动的(我找不到反转顺序并获取的选项:
如果消息命中规则:
运行脚本
然后将 MSG 移动到特定文件夹 所以解决方案是编写脚本并在触发规则时附加。
Public Sub SaveAttach(Item As Outlook.MailItem)
If Item.Attachments.Count > 0 Then
Dim objAttachments As Outlook.Attachments
Dim lngCount As Long
Dim strFile As String
Dim sFileType As String
Dim strFolderpath As String
Dim i As Long
Dim myDestFolder As Outlook.Folder
Set myDestFolder = myInbox.Folders("Mails").Folders("Exported")
Set objAttachments = Item.Attachments
lngCount = objAttachments.Count
For i = lngCount To 1 Step -1
strFile = objAttachments.Item(i).FileName
strFolderpath = "D:\TEMP\"
strFile = strFolderpath & strFile
objAttachments.Item(i).SaveAsFile strFile
Next i
Item.Move myDestFolder
End If
End Sub
将上面的代码放入 ThisOutlookSession 然后连接到规则“运行脚本”可以工作,但是如何扩展上面的代码以将我提取的附件的 MSG 移动到 I.E. 中的另一个 Outlook 子文件夹。邮件\导出\?
编辑:
添加的行
将 myDestFolder 调暗为 Outlook.Folder
设置 myDestFolder = myInbox.Folders("Mails").Folders("Exported")
Item.Move myDestFolder
但还是有问题,VBA 在这种模式下(运行脚本作为规则的一部分)不运行调试并且看不到错误消息,它只是不起作用(我只能设置 msgbox“我在这里”来跟踪脚本的哪一部分不会工作:/
文件树如下所示
1 收件箱(DefaultIncomingMailsFile.ost (IMAP))
2 邮件(LocalFile.pst)
2a 已导出(附件提取后应将邮件移动到的邮件中的子文件夹)
【问题讨论】:
-
要调试您的代码,请将项目传递给它。您可以创建一个单行测试程序
SaveAttach ActiveInspector.CurrentItem。详情在这里stackoverflow.com/questions/11870717/…。
标签: vba outlook move attachment rules