Delete all items in the Outlook Junk and Trash (Deleted Items) folder
2017-01-10 Outlook 0 532
The macros below can be used to delete all items in the Junk and Trash (Deleted Items) folder in Outlook.
For ease of use, attach the first macro to a button in the Quick Access Toolbar:
Sub DeleteAllSpamAndTrash()
' updated 2017-01-10 by OPE
Dim OLF As Outlook.NameSpace, f As Long, objFolder As Folder
Set OLF = GetObject("", "Outlook.Application").GetNamespace("MAPI")
For f = 1 To OLF.Folders.Count
On Error Resume Next
Set objFolder = OLF.Folders(f).Store.GetDefaultFolder(olFolderJunk)
On Error GoTo 0
DeleteAllFolderItems objFolder
Set objFolder = Nothing
On Error Resume Next
Set objFolder = OLF.Folders(f).Store.GetDefaultFolder(olFolderDeletedItems)
On Error GoTo 0
DeleteAllFolderItems objFolder
Set objFolder = Nothing
Next f
Set OLF = Nothing
End Sub
Sub DeleteAllFolderItems(objFolder As Folder)
' updated 2017-01-10 by OPE
Dim i As Long
If objFolder Is Nothing Then Exit Sub
With objFolder
For i = .Items.Count To 1 Step -1
On Error Resume Next
.Items(i).Delete
On Error GoTo 0
Next i
End With
End Sub