2

Does anyone know the VBA code to invoke the "Clean Up Folder" Outlook 2010 command on the right-click menu when right-clicking on a folder?

I have gotten this far in VBA code to get to the folders I want to clean up:

Private Sub CleanUpAllFolders()
Dim Folders As Outlook.Folders
Dim Folder As Outlook.Folder
Set Folders = Session.GetDefaultFolder(olFolderInbox).Parent.Folders
For Each Folder In Folders
    If Left(Folder.Name, 1) = "_" Then
        ' Clean up folder... how do I invoke that command from VBA on this folder?
    End If
Next
End Sub

However, I can't see any method on the Folder object itself that lets me invoke "Clean Up Folder".

How do I invoke one of those right-click menu commands on the current selected folder in VBA?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • I don't see it anywhere obvious in the object model either. You could try the old standby of recording a macro while executing a cleanup of a folder. Looking at the code in the recorded macro might give you a hint regarding where to start looking – barrowc Oct 18 '11 at 22:08
  • This is a great question that I have been looking at hoping to see some feedback. I cant find anything useful in the object model or via google. @barrow, unlike Excel Outlook doesn't offer a macro recorder function – brettdj Oct 20 '11 at 03:08
  • @brettdj Thanks for correcting my misunderstanding. Outlook sometimes seems like the unloved step-child of the Office family – barrowc Oct 20 '11 at 23:52

1 Answers1

2

I am unable to test this, but from what I read this might work.

First find the idMso value for the command. Use this to find the value:

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=3582

Then use Application.CommandBars.ExecuteMso(idMso) to execute the command. Good luck.

JimmyPena
  • 8,694
  • 6
  • 43
  • 64
  • This post might provide more assistance: http://stackoverflow.com/questions/7600181/outlook-object-model-hooking-to-the-conversation-cleanup-feature – JimmyPena Nov 02 '11 at 14:30