提问人:MichaelE 提问时间:11/9/2023 最后编辑:braXMichaelE 更新时间:11/9/2023 访问量:26
删除所有已删除的项目,包括提醒事项
Remove all Deleted items including reminders
问:
我有很多警报,最近发现当它们被删除时,它们只会删除项目并导致问题,所以我正在尝试使用宏删除警报。
Public Sub ClearDeleted()
Dim olNS As NameSpace
Dim deletedFolder As Outlook.MAPIFolder
Set olNS = Outlook.Application.GetNamespace("MAPI")
Set deletedFolder = olNS.GetDefaultFolder(olFolderDeletedItems)
myCount = deletedFolder.Items.Count
For ii = 1 To myCount Step 1
Debug.Print ii & " " & deltedFolder.Items(ii)
Next ii
End Sub
我不是在这里删除,而是打印主题名称,它适用于常规电子邮件,但是如果它收到提醒,它会失败,Object不支持此属性或方法。
我发现,如果我只关注约会并添加。
Dim objAppointment As Outlook.AppointmentItem
'In the loop:
Set objAppointment = deletedFolder.Items.Item(ii)
Debug.Print ii & " " & objAppointment.Subject
这仅适用于警报,但在到达常规电子邮件时会失败,并显示类型不匹配。
如何让一个宏同时处理电子邮件和警报?谢谢。
答:
1赞
Dmitry Streblechenko
11/9/2023
#1
而不是
Dim objAppointment As Outlook.AppointmentItem
用
Dim objAppointment As Object
并检查住宿是否将其标识为预约:Class
26 (OlObjectClass.olAppointment)
if objAppointment.Class = 26 Then
...
您还需要向后循环,否则在循环时会减少集合计数:
dim Items As Object
dim Items as Items
set Items = deletedFolder.Items
myCount = Items.Count
For ii = myCount to 1 Step -1
set Item = Items(ii)
if Item.Class = 26 Then
Item.Delete
End If
next ii
评论
1赞
MichaelE
11/9/2023
谢谢,这很有效。 是工作所需的全部内容,因为约会和电子邮件都有这种方法。很高兴知道约会是 26 级,电子邮件是 53 级。dim Item As Object
.Delete
评论
Debug.Print ii & " " & deltedFolder.Items(ii)
错字For ii = 1 To myCount to 1 Step -1
If TypeOf deletedFolder.Items(ii) Is AppointmentItem Then