vba - Outlook 规则 + VBA:保存附件,然后将邮件移动到所选文件夹
问题描述
我需要对我收到的一些特定邮件使用规则。我必须将附件保存到特定文件夹 IE D:\TEST) 然后将邮件移动到附加到 Outlook 的另一个 FILE 邮箱文件中的特定子文件夹。
我找到并调整了代码以满足我的需要,但 Outlook 规则“麻木”,无法更改规则步骤执行的顺序:
如果味精命中规则:
将 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 移动到 IE Mails\Exported\ 中的另一个 Outlook 子文件夹?
编辑:
添加的行
将 myDestFolder 调暗为 Outlook.Folder
设置 myDestFolder = myInbox.Folders("Mails").Folders("Exported")
Item.Move myDestFolder
但是仍然有问题,并且在此模式下的 VBA(运行脚本作为规则的一部分)不运行调试并且看不到错误消息,它只是不起作用(我只能设置 msgbox“我在这里”来跟踪脚本的哪一部分不起作用: /
文件树看起来像这样
1 收件箱(DefaultIncomingMailsFile.ost (IMAP))
2 封邮件(LocalFile.pst)
2a 已导出(附件提取后应将邮件移动到的邮件中的子文件夹)
解决方案
但是如何扩展上面的代码以将我提取的附件的 MSG 移动到 IE Mailbox\Done\ 中的另一个 Outlook 子文件夹?
您需要使用将Microsoft Outlook 项目移动到新文件夹的类的Move方法。MailItem
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
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 yourTargetFolder
End If
End Sub
推荐阅读
- image-processing - 如何将楔形文字图像(黑白)转换为彩色渐变图像(从白色到黑色)?
- aws-api-gateway - JSON Schema 4 仅验证一个定义
- docker - Docker 无法在 Jenkins 中提取指定的 .NET SDK(未找到 SDK 错误)
- python - 是否可以从本网站的地图中抓取数据?
- c++ - 为另一个函数设置一个“调用者”函数是否相关(如变量的设置器)
- css - 使用 fop-2.2 将 svg 转换为 pdf 时,stroke-opacity 对 svg:text 没有影响
- c++ - 在 Visual Studio 中解决忽略的 constexpr?
- javascript - 无法在 JSON-SERVER 中获取对象键数据
- java - 不断出现错误:尽管设置了 PATH 和 CLASSPATH 变量,但无法找到或加载主类
- nsis - NSIS:将当前用户目录设置为 nsis 中的默认安装目录