PDA

View Full Version : Outlook VBA: Listen for new emails and trigger popup Msgbox



Cheesecube
04-13-2020, 10:09 PM
Hi, I intend to trigger some code immediately upon receipt of a new email in Outlook.

I am following the code exactly word for word as written in this website:
https://www.tachytelic.net/2017/10/how-to-run-a-vba-macro-when-new-mail-is-received-in-outlook/

This should be the basis for me to edit and run more complex code segments

But even with this basic code demo, the new email event listener does not work.

I restarted Outlook a few times and sent the email to my Outlook inbox again and again

Any idea why this code isn't working? Thanks

gmayor
04-14-2020, 01:12 AM
I can't see any obvious reason why it wouldn't work - though if it's a security issue, see
https://www.gmayor.com/create_and_employ_a_digital_cert.htm (http://www.gmayor.com/create_and_employ_a_digital_cert.htm)
You could use instead a rule that runs on all incoming messages, with a script

Sub MailHasArrived(Item As Outlook.MailItem)
If TypeName(Item) = "MailItem" Then
'do stuff with Item
MsgBox Item.Subject
End If
lbl_Exit:
Exit Sub
End Sub
If the script option isn't available see https://www.slipstick.com/outlook/rules/outlook-run-a-script-rules/