I wrote a macro in Outlook that opens an Excel file, then runs another macro inside the Excel spreadsheet. The Excel macro in turn saves some charts as PDF files, and opens up Outlook to email them as attachments.
When I run this macro with Outlook already open, it works fine. However, if I assign the macro to execute in the Application_Startup event upon startup, I get an error in the Excel macro that says ActiveX cannot create the desired object. It appears on the first line of this code:
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
I did Dim both variables as Objects. Sorry for the novice question, but I have been unable to find the explanation with several hours of searching.
Why does this only occur when the macro runs during startup? Does this have something to do with Excel or Outlook not being fully loaded at the time the macro attempts to run?