Hello, I am having trouble with my events in outlook, not sure if I am missing something or not.
I am trying to trigger a macro when the selected mail item in outlook is opened.
Using the code below, I can successfully trap the event and display the msgbox when double clicking the first item in my inbox.
However I am wanting to be able to display the msgbox for any email that is double clicked.
I am trying to use the code below, but it doesnt seem to work. Every time i double click on the email it is opening the email as normal and not triggering the msgbox.
Any ideas what I need to do different?
Thank you for your help.
I am trying to trigger a macro when the selected mail item in outlook is opened.
Using the code below, I can successfully trap the event and display the msgbox when double clicking the first item in my inbox.
Code:
Public WithEvents myItem As Outlook.MailItem
Private Sub Application_ItemLoad(ByVal Item As Object)
Set myItem = Application.Session.GetDefaultFolder(olFolderInbox).Items(1)
End Sub
Private Sub myItem_Open(Cancel As Boolean)
Cancel = True
MsgBox "opened an item"
End Sub
However I am wanting to be able to display the msgbox for any email that is double clicked.
I am trying to use the code below, but it doesnt seem to work. Every time i double click on the email it is opening the email as normal and not triggering the msgbox.
Any ideas what I need to do different?
Code:
Public WithEvents myItem As Outlook.MailItem
Private Sub Application_ItemLoad(ByVal Item As Object)
Set myItem =Application.ActiveExplorer.Selection.Item(1)
End Sub
Private Sub myItem_Open(Cancel As Boolean)
Cancel = True
MsgBox "opened an item"
End Sub
Thank you for your help.