This example prompts the user to remove a folder from the Deleted Items folder if the folder is empty. The sample code must be placed in a class module, and the Initialize_handler
routine must be called before the event procedure can be called by Microsoft Outlook.
Dim myolapp As New Outlook.Application
Dim WithEvents myFolders As Outlook.Folders
Sub Initialize_handler()
Set myNS = myolapp.GetNamespace("MAPI")
Set myFolders = myNS.GetDefaultFolder(olFolderDeletedItems).Folders
End Sub
Private Sub myFolders_FolderChange(ByVal Folder As Outlook.MAPIFolder)
If Folder.Items.Count = 0 Then
MyPrompt = Folder.Name & " is empty. Do you want to delete it?"
If MsgBox(MyPrompt, vbYesNo + vbQuestion) = vbYes Then
Folder.Delete
End If
End If
End Sub