【发布时间】:2018-01-01 14:09:07
【问题描述】:
我需要从共享邮箱中永久删除超过特定年龄的电子邮件。
自动存档功能不会影响共享邮箱,并且每次我尝试运行规则来执行此操作时,它都会失败并且不采取任何操作。
我一直在手动清除数百封需要绝对年龄的电子邮件(当你有超过 300k 的邮件时),因为当我这样做时它会填满我自己删除的项目。
编辑:
我一直在切碎我发现尝试实现这一目标的随机代码。我可以访问部门内的其他 6 个共享邮箱。我一直在查看 GetSharedDefaultFolder 函数,但它没有得到很好的解释,并且在我的 bodged 尝试运行时通常会出错。我不确定收件人功能需要什么,因为我已经尝试过邮箱名称和地址。在这种情况下,MS 在线资源不是很有帮助:
编辑 2:
我已将我的代码编辑到下面。在这个版本中,我在For intCount = olSharedBox.Items.Count To 1 Step -1 行收到溢出错误。
由于该框中有超过 30 万封电子邮件,我认为它现在正在寻找正确的东西,但不确定解决方法。是不是不能从收件箱旁边显示的预先统计的数字中得到当前的数字?
Sub DeleteOldSharedMail()
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olMailItem As Outlook.MailItem
Dim objVariant As Variant
Dim lngMovedItems As Long
Dim intCount As Integer
Dim intDateDiff As Integer
Dim olSharedBox As Folder
Dim mbOwner As Outlook.Recipient
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set mbOwner = olNS.CreateRecipient("mailbox@email.com")
Set olSharedBox = olNS.GetSharedDefaultFolder(mbOwner, olFolderInbox)
For intCount = olSharedBox.Items.Count To 1 Step -1
Set objVariant = olSharedBox.Items.Item(intCount)
DoEvents
If objVariant.Class = olMail Then
intDateDiff = DateDiff("d", objVariant.SentOn, Now)
' Set number of days
If intDateDiff > 180 Then
objVariant.Delete
Call ClearDeletedFolder ' Working. Will change to call every 100 emails deleted after first run.
'count the # of items moved
lngMovedItems = lngMovedItems + 1
' No need to run the IF statement on the rest of the mailbox assuming the macro runs from oldest to newest.
'Else: GoTo Marker
End If
End If
Next
' Display the number of items that were moved.
Marker:
MsgBox "Moved " & lngMovedItems & " messages(s)."
End Sub
【问题讨论】:
-
您在哪个办公室工作?有什么试过的可以分享吗?
-
我正在使用 Office 2013 并已编辑我的问题以包括第一次尝试,从其他资源中收集我可以收集的内容。我想念excel VBA。相比之下,Outlook 显得很奇怪。
-
Dim intCount As Long