Hi All,
I would like to run a macro in outlook. This macro should get triggered in when i close a email or when press escape to close the email.
Is there any sample i can refer to.
Regards
Hi All,
I would like to run a macro in outlook. This macro should get triggered in when i close a email or when press escape to close the email.
Is there any sample i can refer to.
Regards
i have tried the below but its not getting executed it seems but nothing is happening
Public WithEvents colInspectors As Outlook.Inspectors Public WithEvents myInspector As Outlook.Inspector Private Sub Application_Startup() MsgBox "Test1" Set colInspectors = Application.Inspectors End Sub Private Sub col_NewInspector(ByVal Inspector As Inspector) If Inspector.CurrentItem.Class = olMail Then ' only for mail items MsgBox "Test2" Set myInspector = Inspector End If End Sub Private Sub myInspector_Close() MsgBox "Test3" Set myInspector = Nothing End Sub
Last edited by Aussiebear; 05-25-2022 at 05:26 AM. Reason: Added code tags to supplied code
Try putting this into the ThisOutlookSession code module, close outlook and then reopen.
Open a new mail and then try to close it. You can see the code is running when you try to close the mail or esc the mail:
Dim WithEvents Insps As Inspectors Dim WithEvents mItem As MailItem Private Sub Application_Startup() Set Insps = Application.Inspectors End Sub Private Sub Insps_NewInspector(ByVal Inspector As Inspector) If TypeOf Inspector.CurrentItem Is MailItem Then Set mItem = Inspector.CurrentItem End If End Sub Private Sub mItem_Close(Cancel As Boolean) MsgBox "Unable to close due to georgiboy!" Cancel = True End Sub
Georgiboy... its working.. thank you very much...