Outlook宏-为什么不从已删除的文件夹中删除所有项目? [英] outlook macro - why doesn't this delete all items from deleted folder?

查看:144
本文介绍了Outlook宏-为什么不从已删除的文件夹中删除所有项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Outlook中具有以下宏来清除已删除的文件夹.这很奇怪,因为它似乎并没有删除所有条目.我必须运行几次,以清除已删除邮件文件夹. (通常2或3次).每次删除文件夹中的已删除项目的数量都会减少,但是我不明白为什么在第一次尝试时不会清除所有内容.

I have the following macro in outlook to clear my deleted folder. its strange as it doesn't seem to delete all entries. I have to run this a few times for it to clear to deleted items folder. (usually 2 or 3 times). Each time the number of deleted items in the folder does get reduced but I don't understand why everything doesn't get wiped out in the first go.

这是我的代码;有什么问题吗?

Here is my code; Anything wrong?

Public Sub EmptyDeletedEmailFolder()

    Dim outApp As Outlook.Application
    Dim deletedFolder As Outlook.MAPIFolder
    Dim item As Object
    Dim entryID As String

    Set outApp = CreateObject("outlook.application")
    Set deletedFolder = outApp.GetNamespace("MAPI").GetDefaultFolder(olFolderDeletedItems)

    For Each item In deletedFolder.Items
        item.Delete             ' Delete from mail folder
    Next

    Set item = Nothing
    Set deletedFolder  = Nothing
    Set outApp = Nothing

End Sub

推荐答案

尝试:

For i = deletedFolder.Items.Count To 1 Step -1
    deletedFolder.Items(i).Delete             '' Delete from mail folder
Next

从集合中删除项目可能会有问题.

There can be problems with deleting items from a collection.

这篇关于Outlook宏-为什么不从已删除的文件夹中删除所有项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆