Building custom solutions that extend, automate, and integrate Microsoft 365 apps.
In Outlook, press Alt + F11 to open the VBA editor. In the left pane, expand “Microsoft Outlook Objects” and double-click “ThisOutlookSession.” Paste your macro code there if you are using the Application_NewMailEx event, because that event must live inside ThisOutlookSession to run automatically when mail arrives.
Your macro structure should look something like this:
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
your code
End Sub
If your code saves Excel attachments to OneDrive, you would typically use the Attachment.SaveAsFile method and point it to your OneDrive folder path, for example: C:\Users\YourName\OneDrive\Attachments\
After pasting the code, save the project and restart Outlook. Then go to File > Options > Trust Center > Trust Center Settings > Macro Settings and enable notifications or allow signed macros. Also make sure “Programmatic Access” is not blocking automation.
Finally, test by sending yourself an email with an Excel attachment. The macro only runs when new mail arrives in Outlook, not on existing messages already in the Inbox.
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin