locked
Macro button to delete folders like Trash RRS feed

  • Question

  • I like to delete items inside folder called trash or Deleted items folder. How to do it with one click as there are many email accounts?
    • Edited by toplisek Wednesday, September 27, 2017 12:44 PM
    Wednesday, September 27, 2017 12:43 PM

All replies

  • Hi,

    You may try using the following macro:

    Sub EmptyDeletedItems()
    Dim olApp As Outlook.Application
    Dim olNS As Outlook.NameSpace
    Dim objExpl As Outlook.Explorer
    Dim mboxCount As Long
    Dim i As Long
    Dim deletedItemsFolder As Outlook.folder
     
    Set olApp = Application
    Set olNS = olApp.GetNamespace("MAPI")
    Set objExpl = olApp.ActiveExplorer
     
    mboxCount = olNS.Folders.Count
    For i = 1 To mboxCount
      On Error Resume Next
      Set deletedItemsFolder = olNS.Folders(i).Folders("Deleted Items")
      If Err = 0 Then
        On Error GoTo 0
        objExpl.SelectFolder deletedItemsFolder
         objExpl.CommandBars.ExecuteMso ("EmptyFolder")
      End If
    Next i
     
    objExpl.SelectFolder olNS.GetDefaultFolder(olFolderInbox)
     
    End Sub

    See the following article for detailed steps:

    https://www.slipstick.com/developer/code-samples/empty-multiple-deleted-items-folders-using-a-macro/

    (Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.)

    Hope this helps.

    Regards,

    Steve Fan


    Please remember to mark the replies as answers if they helped.

    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Proposed as answer by Steve Fan Thursday, September 28, 2017 2:41 AM
    Thursday, September 28, 2017 2:41 AM
  • When i go to this folder it will empty but when I go again into this folder it will show again. Is this my mistake?

    How to delete from this folder Deleted all items in all accounts?

    Thursday, October 5, 2017 1:06 PM
  • Hi,

    Do you mean the emptied items will restore to the Deleted Items folder when switching to another folder and then switching back?

    The macro runs correctly in my environment and it works for all accounts configured in the same mail profile with one-click.

    Regards,

    Steve Fan


    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, October 6, 2017 9:48 AM
  • Strange. I have checked again. It is a message like image.


    • Edited by toplisek Friday, October 6, 2017 11:10 AM
    Friday, October 6, 2017 11:09 AM