To work with the currently selected item (not opened) in the message list, you will need to reference the ActiveExplorer and will use the ActiveExplorer method to get the item in the Explorer window. (This is used for all Outlook items that are selected but not opened: appointments, contacts, tasks, etc.)
Set objItem = objApp.ActiveExplorer.Selection.Item(1)
When you are working with an Outlook item that is open and has focus, it uses the ActiveInspector method. The code you need to work with Inspectors is.
Set objItem = objApp.ActiveInspector.CurrentItem
To help remember which is which, think of the main Outlook window as Windows Explorer. When you work with items in this window, you'll use Explorer.
Use macros with both opened and selected items
When you want to use the macro with both open or selected items, you'll use this function to determine if the item is open or selected. You'll call the function in your code in this manner:
Set objItem = GetCurrentItem()
You'll need to put one copy of this function in a module and can use the function in many macros.
Function GetCurrentItem() As Object Dim objApp As Outlook.Application Set objApp = Application On Error Resume Next Select Case TypeName(objApp.ActiveWindow) Case "Explorer" Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1) Case "Inspector" Set GetCurrentItem = objApp.ActiveInspector.CurrentItem End Select Set objApp = Nothing End Function
These articles are applicable to all versions of Outlook: