通过 Excel 范围创建 Outlook 文件夹循环

通过 Excel 范围创建 Outlook 文件夹循环

我能够从 excel 的第一列循环获取发件人姓名,现在我正在尝试在下面的代码中创建文件夹循环,但它显示错误 !!!

Sub MoveItems()
Dim myNameSpace As 
Outlook.Namespace

Dim myInbox As Outlook.Folder
Dim myDestFolder As Outlook.Folder
Dim myItems As Outlook.Items
Dim myItem As Object

Set myNameSpace =   Outlook.Application.GetNamespace("MAPI.   ")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderinbox)
Set myItems = myInbox.Items


Dim varSearchTerms As Variant
varSearchTerms = Range("a1:a3").Value 'refering to excel range for sender names

Dim varSearchTerm As Variant
For Each varSearchTerm In varSearchTerms

Set myItem = myItems.Find("[SenderName] = '" & varSearchTerm & "'")
 While TypeName(myItem) <> "Nothing"
Set myDestFolder = myInbox.Folders(range("b2"b3").value)
       myItem.Move myDestFolder
     Set myItem = myItems.FindNext
  Wend
   Next

 End Sub

此阶段显示错误

  Set myItem = myItems.Find("[SenderName] = '" & varSearchTerm & "'")
     While TypeName(myItem) <> "Nothing"
    Set myDestFolder = myInbox.Folders(range("b2"b3").value)
           myItem.Move myDestFolder
         Set myItem = myItems.FindNext

有人能建议我该怎么做吗?

相关内容