对于每个没有拿起所有电子邮件

时间:2018-08-20 21:15:43

标签: vba outlook outlook-vba

我在每个循环中都使用a来循环过滤器上的所有电子邮件,但是我总是留下一些电子邮件。

我需要多次运行此脚本才能清理它。

我该如何解决?

Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim InboxMsg As Object
Dim Inbox As Outlook.Folder
Set objOutlook = Application
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set Inbox = objNamespace.GetDefaultFolder(olFolderInbox)
Dim myRestrictItems As Outlook.Items
 Dim filter As String

'Set Items = Inbox.Items
  filter = "[SenderEmailAddress] = 'tmeadmin@dm5cbs.on.rogers.ca'  or [SenderEmailAddress] = 'tmeadmin@dm5cbr.on.rogers.ca'" _
  & "or [SenderEmailAddress] = 'tmeadmin@dcobyj-030.qc.rogers.ca'" _
  & "or [SenderEmailAddress] = 'tmeadmin@dmobeo-030.on.rogers.ca'"
 Set myRestrictItems = Inbox.Items.Restrict(filter)
 MsgBox (myRestrictItems.Count)
 Set MoveToFolder = objNamespace.Folders("archive").Folders("INBOX").Folders("rogers_ALERTS")
 For Each mail In myRestrictItems
 mail.Move (MoveToFolder)
 Next


End Sub

1 个答案:

答案 0 :(得分:1)

当然-您正在修改迭代器中的集合。使用从计数到1的向下“ for”循环(步骤-1)