【发布时间】:2016-05-10 08:54:45
【问题描述】:
我目前在运行 VBA 脚本时遇到了一个小问题。
Sub MovePathErrors(Item As Outlook.MailItem)
If Item.Attachments.Count > 0 Then
Dim attCount As Long
Dim strFile As String
Dim sFileType As String
attCount = Item.Attachments.Count
For i = attCount To 1 Step -1
strFile = Item.Attachments.Item(i).FileName
sFileType = LCase$(Right$(strFile, 4))
Select Case sFileType
Case ".ber"
' do something if the file types are found
' this code moves the message
Item.Move (Session.GetDefaultFolder(olFolderInbox).Folders(".PathErrors"))
' stop checking if a match is found and exit sub
GoTo endsub
End Select
Next i
End If
基本上,上面的代码将所有带有包含 .ber 文件类型附件的邮件项目从我的收件箱文件夹移动到“.PathErrors”子文件夹 - 这非常有效。
但是,如果邮件包含 .ber 文件类型的附件,我想要将邮件从不同的子文件夹“.AllPathMails”移动到“.PathErrors”。
我尝试了以下代码,但它不起作用:
Sub MovePathErrors(Item As Outlook.MailItem)
If Item.Attachments.Count > 0 Then
Dim attCount As Long
Dim strFile As String
Dim sFileType As String
attCount = Item.Attachments.Count
For i = attCount To 1 Step -1
strFile = Item.Attachments.Item(i).FileName
sFileType = LCase$(Right$(strFile, 4))
Select Case sFileType
Case ".ber"
' do something if the file types are found
' this code moves the message
Item.Move (Session.GetDefaultFolder(".AllPathMails").Folders(".PathErrors"))
' stop checking if a match is found and exit sub
GoTo endsub
End Select
Next i
End If
我在这里做错了吗? 我认为可能是 'Session.GetDefaultFolder' 部分有问题?
【问题讨论】:
-
欢迎来到 *。我正在努力执行第一段代码来移动带有“.ber”附件的电子邮件。请您指出如何执行代码以及放置它的位置。
-
嗨@Jean-PierreOosthuizen,谢谢。请参阅 Diane Poremsky 的实现:[link] (slipstick.com/developer/code-samples/…)
-
“.AllPathMails”文件夹和“.PathErrors”文件夹到底在哪里?它们是收件箱的子文件夹还是文件柜的一部分?
-
@Jean-PierreOosthuizen 是的,这些只是我的 Outlook 收件箱的子文件夹。