【发布时间】:2015-07-22 17:28:41
【问题描述】:
Public Sub RemDups()
Dim t As Items, _
i As Integer, _
arr As Collection, _
f As Folder, _
parent As Folder, _
target As Folder, _
miLast As MailItem, _
mi As MailItem
Set parent = Application.GetNamespace("MAPI").PickFolder
Set target = Application.GetNamespace("MAPI").PickFolder
For Each f In parent.Folders
Set t = f.Items
t.Sort "[Subject]"
i = 1
Set miLast = t(i)
Set arr = New Collection
While i < t.Count
i = i + 1
If TypeName(t(i)) = "MailItem" Then
Set mi = t(i)
If miLast.Subject = mi.Subject And miLast.Body = mi.Body _
And miLast.ReceivedTime = mi.ReceivedTime Then
arr.Add mi
Else
Set miLast = mi
End If
End If
Wend
For Each mi In arr
mi.Move target
Next mi
Next f
End Sub
设置 miLast = t(i) 给出“运行时错误'440' 数组索引超出范围 请帮忙
【问题讨论】:
-
当您收到该错误时,
f.Items.Count的值是多少? -
当我编译代码时,我得到的只是“运行时错误”。它没有给出任何计数
-
使用t.Item(i)方法通过集合中的索引获取item。
标签: arrays vba sorting outlook