我目前在运行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'部分有问题?