FolderChange Event

Microsoft Outlook Visual Basic

Occurs when a folder in the specified Folders collection is changed. This event is not available in Microsoft Visual Basic Scripting Edition (VBScript).

Sub object_FolderChange(ByVal Folder As MAPIFolder)

object    An expression that evaluates to a Folders collection object.

Folder Required. The MAPIFolder that was changed.

Example

This Microsoft Visual Basic/Visual Basic for Applications (VBA) 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