VBA Code to run Clean up Folder and Subfolders RRS feed

  • Question

  • I want to write some code in Outlook 2016 VBA to loop through some offline folders and run the "Clean Up Folder & Subfolders"  command from the menu (Home Ribbon).  However, nothing I have found online will work.  There are several comments to use the commandbars object from the ActiveExplorer or ActiveInspector obfects, but the CommandBars object does not exist within those objects in Outlook 2016.  Anyone have a way to accomplish this task?  I have run through the object browser for the CommandBars object and any Ribbon objects, but cannot find any code that I can even get to compile.

    • Edited by Ltl Bear Friday, June 16, 2017 6:42 PM
    Friday, June 16, 2017 6:41 PM

All replies

  • How about something like this?  Make sure you test it thoroughly, before you deleting deleting things.

    Sub GetRssItem()
    Dim myNameSpace As Outlook.NameSpace
    Dim myFolder As Outlook.Folder
    Dim subFolder As Outlook.Folder
    Dim myItem As Object
    Set myNameSpace = Application.GetNamespace("MAPI")
    Set myFolder = myNameSpace.GetDefaultFolder(olFolderRssFeeds)
    For i = 1 To 18
    Set subFolder = myFolder.Folders(i)
       Debug.Print subFolder
          For Each myItem In subFolder.Items
            If InStr(myItem.Subject, "[on hold]") > 0 Then
                Debug.Print myItem.Subject
            End If
          Next myItem
    Next i
    MsgBox ("ALL DONE!!")
    End Sub


    Monday, July 10, 2017 3:54 AM