清理已删除文件夹的VBA脚本无效

时间:2014-02-17 20:15:27

标签: vba outlook

我正在尝试在已删除的文件夹中移动主题行中包含“Xtremevbtalk”的超过21天的电子邮件。这是代码:

Sub emptydeletedfolder()
Dim oSource As Outlook.MAPIFolder
Dim oTarget As Outlook.MAPIFolder
Dim Date21days As Date
Dim ItemsOverDays As Outlook.Items

Dim DateToCheck As String

Date21days = DateAdd("d", -21, Now())
Date21days = Format(Date21days, "mm/dd/yyyy")


Set oSource = Application.Session.GetDefaultFolder(olFolderDeletedItems)
Set oTarget = oSource.Folders("_old")

DateToCheck = "[Received] <= """ & Date21days & """"

Set ItemsOverDays = oSource.Items.Restrict(DateToCheck)

For i = ItemsOverDays.Count To 1 Step -1

If ItemsOverDays.Item(itm.Subject, "Xtremevbtalk") > 0 Then
    ItemsOverDays.Item(i).Move oTarget
    End
End If
Next

Set ItemsOverDays = Nothing
Set oTarget = Nothing
Set oSource = Nothing
End Sub

当我单步执行代码时,它在行中失败:如果ItemsOverDays.Item(itm.Subject,“Xtremevbtalk”)&gt; 0然后

代码在没有if语句的情况下运行正常,删除了超过21天的所有电子邮件,不知道如何编写此行,任何建议都将是最有帮助的

由于 ģ

1 个答案:

答案 0 :(得分:0)

尝试

如果是InStr(ItemsOverDays.Item(I).Subject,&#34; Xtremevbtalk&#34;)&gt; 0然后