DimWithEvents currentExplorer As Outlook.Explorer = NothingPrivateSub ThisApplication_Startup(ByVal sender AsObject, _
ByVal e As System.EventArgs) HandlesMe.Startup
currentExplorer = Me.Explorers.Application.ActiveExplorer
AddHandler currentExplorer.SelectionChange, AddressOf _
currentExplorer_Event
EndSubPublicSub currentExplorer_Event()
Dim selectedFolder As Outlook.MAPIFolder = _
Me.ActiveExplorer().CurrentFolder
Dim expMessage AsString = "Your current folder is " _
& selectedFolder.Name & "." & vbCrLf
Dim itemMessage AsString = "Item is unknown."TryIfMe.ActiveExplorer.Selection.Count > 0 ThenDim selObject AsObject = Me.ActiveExplorer _
.Selection.Item(1)
If (TypeOf selObject Is Outlook.MailItem) ThenDim mailItem As Outlook.MailItem = _
TryCast(selObject, Outlook.MailItem)
itemMessage = "The item is an e-mail message." & _
" The subject is " & mailItem.Subject & "."
mailItem.Display(False)
ElseIf (TypeOf selObject Is Outlook.ContactItem) ThenDim contactItem As Outlook.ContactItem = _
TryCast(selObject, Outlook.ContactItem)
itemMessage = "The item is a contact." & _
" The full name is " & _
contactItem.Subject & "."
contactItem.Display(False)
ElseIf (TypeOf selObject Is Outlook. _
AppointmentItem) ThenDim apptItem As Outlook.AppointmentItem = _
TryCast(selObject, Outlook.AppointmentItem)
itemMessage = "The item is an appointment." _
& apptItem.Subject & "."ElseIf (TypeOf selObject Is Outlook.TaskItem) ThenDim taskItem As Outlook.TaskItem = _
TryCast(selObject, Outlook.TaskItem)
itemMessage = "The item is a task." & _
" The body is " & taskItem.Body & "."ElseIf (TypeOf selObject Is Outlook.MeetingItem) ThenDim meetingItem As Outlook.MeetingItem = _
TryCast(selObject, Outlook.MeetingItem)
itemMessage = "The item is a meeting item. " & _
"The subject is " & meetingItem.Subject & "."EndIfEndIf
expMessage = expMessage & itemMessage
Catch ex As Exception
expMessage = ex.Message
EndTry
MessageBox.Show(expMessage)
EndSub