Home > Software engineering >  Can VBA code run after an application is closed?
Can VBA code run after an application is closed?

Time:05-17

I am using the ItemAdd event to watch for new Outlook emails. Does this event work while the application is closed?

Currently, my macro launches upon initial startup using the "Application_Startup()" event, and then initializes a class module containing a sub routine that is trigged with the "ItemAdd" event. If I close Outlook, will this macro still be watching for a new "ItemAdd" event?

Thanks!

CodePudding user response:

No, it will not - the event is fired by the application only, so no application - no event.

Keep in mind that if this is a cached profile, these events will fire on application startup when the cached mailbox (OST) is updated. You can also work around this by processing all unread emails on startup (assuming they stay unread). Or you can persist the MailItem.ReceivedTime property of your last processed message and process all emails newer than that on startup.

  • Related