Outlook VBA - How to empty the deleted items folder for specific mailboxes
Hi.
I am using Outlook 2016. I am trying to figure out the code to empty the Deleted Items folder for 2 specific mailboxes. I found some code on the internet, but I can't figure out how to change it so that it only processes the Deleted Items folders in the 2 specific mailboxes that I want. It goes through ALL mailboxes. This is the code I found:
Code:
Private Sub Application_Startup()
Dim objStores As Outlook.Stores
Dim objStore As Outlook.Store
Dim objPSTFile As Outlook.Folder
Dim objFolders As Outlook.Folders
Dim objFolder As Object
Set objStores = Outlook.Application.Session.Stores
'Process all Outlook PST files in your Outlook
For Each objStore In objStores
Set objPSTFile = objStore.GetRootFolder
For Each objFolder In objPSTFile.Folders
Call ProcessFolders(objFolder)
Next
Next
End Sub
Sub ProcessFolders(ByVal objCurrentFolder As Outlook.Folder)
Dim i, n As Long
If objCurrentFolder.Name = "Deleted Items" Then
'Delete all the items in "Deleted Items" folder
For i = objCurrentFolder.Items.Count To 1 Step -1
objCurrentFolder.Items.Item(i).Delete
'Delete all the subfolders under "Deleted Items" folder
For n = objCurrentFolder.Folders.Count To 1 Step -1
objCurrentFolder.Folders.Item(n).Delete
Next
Next
End If
End Sub
Can anyone help me with this problem?
Thanks!
Karin