我有以下 Visual Basic 脚本,它应该将我的收件箱中的电子邮件移动到特定文件夹,但是当我运行它时,什么也没有发生。我对 VBA 很陌生,所以对为什么有点困惑。有什么突出的吗,或者您对如何找出为什么会发生这种情况('nt)有什么建议?谢谢!
代码:
Sub Move_Emails()
Set myNameSpace = Application.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(6)
Set myItems = myInbox.Items
Dim myItem As Outlook.MailItem
Dim MailItem As Object
Dim sn As String
For Each MailItem In myInbox.Items
sn = MailItem.SenderName
If sn = "John Doe" Then
Set myDestFolder = myInbox.Folders("Folder1")
ElseIf sn = "Jane Smith" Then
Set myDestFolder = myInbox.Folders("Folder2")
ElseIf sn = "Bob Jones" Then
Set myDestFolder = myInbox.Folders("Folder3")
End If
Set myItem = myItems.Find("[SenderName] = sn")
While TypeName(myItem) <> "Nothing"
myItem.Move myDestFolder
Set myItem = myItems.FindNext
Wend
Next
End Sub