These two samples contains the basic code for working with all items in a selected folder or selected items in a folder. The code sample prints the item subject in the Immediate window (Ctrl+6).
Because the code uses generic objects instead of specific objects, it will work with all items types.
Work with all items in any folder
Option Explicit Public Sub DoSomethingFolder() Dim objOL As Outlook.Application Dim objOutlookItem As Object Dim objItems As Outlook.Items Dim objFolder As Outlook.MAPIFolder Dim obj As Object Set objOL = Outlook.Application Set objFolder = objOL.ActiveExplorer.CurrentFolder Set objItems = objFolder.Items For Each obj In objItems With obj ' do whatever Debug.Print .Subject End With Next Set obj = Nothing Set objOutlookItem = Nothing Set objItems = Nothing Set objFolder = Nothing Set objOL = Nothing End Sub
Work with Selected items in any folder
Option Explicit Public Sub DoSomethingSelection() Dim Session As Outlook.NameSpace Dim currentExplorer As Explorer Dim Selection As Selection Dim obj As Object Set currentExplorer = Application.ActiveExplorer Set Selection = currentExplorer.Selection For Each obj In Selection With obj ' do whatever Debug.Print .Subject End With Next Set Session = Nothing Set currentExplorer = Nothing Set obj = Nothing Set Selection = Nothing End Sub