Private WithEvents olkExp As Outlook.Explorer
Private WithEvents olkMsg As Outlook.MailItem
Private bolUnread As Boolean
Private Sub Class_Initialize()
Set olkExp = Outlook.Application.ActiveExplorer
olkExp_SelectionChange
End Sub
Private Sub Class_Terminate()
Set olkMsg = Nothing
Set olkExp = Nothing
End Sub
Private Sub olkExp_SelectionChange()
If olkExp.Selection.Count = 1 Then
If olkExp.Selection(1).Class = olMail Then
Set olkMsg = olkExp.Selection(1)
bolUnread = olkMsg.UnRead
Else
Set olkMsg = Nothing
End If
End If
End Sub
Private Sub olkMsg_Open(Cancel As Boolean)
If bolUnread Then
'This is where the code goes that fires when a previously unread item is opened'
MsgBox "You just opened an unread message"
End If
End Sub
Rules only run when an item is sent or received. A rule cannot be triggered by clicking/opening an item. Do you want the program to launch for every message you open or only certain ones?