我有一個問題,我需要從共享郵箱中刪除超過特定年齡的郵件。Outlook VBA永久刪除共享郵箱中的舊電子郵件
不幸的是,自動存檔功能不會影響共享郵箱,並且每次我嘗試運行規則來執行此操作時,都會失敗並且不會執行任何操作。我一直不得不手動清除這個郵箱裏的數百封電子郵件,這個郵箱需要絕對的年齡(當你有30多萬個坐在那裏的時候......),因爲它填補了我自己刪除的項目。
我非常精通Excel VBA,但我不知道Outlook如何處理事情。我一直在尋找一種方法來做到這一點,但我還沒有找到任何可靠的,我可以使用,這是很好的註釋教我。
有沒有其他人曾經做過同樣的事情?我不能是唯一一個想要這樣做的人嗎?
編輯: 我一直在斬斷我發現嘗試實現這一點的隨機代碼。我有權訪問我的部門中的其他6個共享郵箱。我一直在看GetSharedDefaultFolder函數,但它不是很好解釋,並且通常在我的懶散嘗試運行時出現錯誤。我不確定收件人功能需要什麼,因爲我嘗試過郵箱名稱和地址。該MS網絡資源不是非常有幫助在這種情況下:
編輯2:
我已經編輯我的代碼下面。在這個版本中,我得到一個溢出錯誤的線對於intCount = olSharedBox.Items.Count到1步-1 -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("[email protected]")
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
是否運行了辦公室?有沒有試過你可以分享的東西? – 0m3r
我正在使用Office 2013,並編輯了我的問題以包含第一次嘗試,從其他資源中收集我可以獲得的內容。我想念優秀的VBA。相比之下,展望似乎很奇怪。 – JaayB
Dim intCount As Long – niton