title: Automation Error System Call Failed - Outlook and Excel VBA
body: <p>Quite stumped here. Getting Run-Time Error -2147417856 (80010100) Automation Error System Call Failed</p>
  
  <p>I have a couple outlook rules that run a scripts.</p>
  
  <p>The first Outlook script opens an excel file and runs the macros in the excel file and repeats this two time (as seen below). Then the Outlook script closes Excel and exits the sub. The error occurs while in the second Excel file's macros. </p>
  
  <pre><code>'First File
  
  Set xlApp = CreateObject("Excel.Application")
  
  xlApp.Visible = False
  
  xlApp.Application.DisplayAlerts = False
  
  xlApp.Application.EnableEvents = False
  
  Set xlWork = xlApp.Workbooks.Open(strPath &amp; "\File1.xlsm")
  
  xlWork.Application.Run "Macro1_Module.Macro1"
  
  xlWork.Application.Run "Macro2_Module.Macro2"
  
  xlWork.SaveAs FileName:=savepath1, FileFormat:=xlOpenXMLWorkbook
  
  xlWork.Close
  
  Set xlWork = Nothing
  
  xlApp.Application.DisplayAlerts = True
  
  xlApp.Application.EnableEvents = True
  
  xlApp.Quit
  
  Set xlApp = Nothing
  
  'Second File
  
  Set xlApp = CreateObject("Excel.Application")
  
  xlApp.Visible = False
  
  xlApp.Application.DisplayAlerts = False
  
  xlApp.Application.EnableEvents = False
  
  Set xlWork = xlApp.Workbooks.Open(strPath &amp; "\File2.xlsm")
  
  xlWork.Application.Run "Macro1_Module.Macro1"
  
  xlWork.Application.Run "Macro2_Module.Macro2"
  
  xlWork.SaveAs FileName:=savepath2, FileFormat:=xlOpenXMLWorkbook
  
  xlWork.Close
  
  Set xlWork = Nothing
  
  xlApp.Application.DisplayAlerts = True
  
  xlApp.Application.EnableEvents = True
  
  xlApp.Quit
  
  Set xlApp = Nothing
  </code></pre>
  
  <p>The macros in the excel file create an email using data in Excel and sends it via Outlook (CreateObject("Outlook.Application")). This uses the below code to generate the email. </p>
  
  <pre><code>Set OutApp = CreateObject("Outlook.Application")
  
  OutApp.Session.Logon
  
  Set Outmail = OutApp.CreateItem(0)
  
  On Error Resume Next
  
  With Outmail
  
  .To = ""
  
  .CC = ""
  
  .BCC = ""
  
  .Subject = "Test"
  
  .HTMLBody = "TEST"
  
  .Attachments.Add (ActiveWorkbook.Path &amp; "\" &amp; ActiveWorkbook.Name)
  
  End With
  
  Outmail.Display
  
  On Error GoTo 0
  
  Set Outmail = Nothing
  
  Set OutApp = Nothing
  </code></pre>
  
  <p>The second Outlook script can sometime get triggered while the first is running. I thought that the rules created a backlog and ran one after another. When the first script is running in Outlook then Excel, it errors after the second email comes in to trigger the second Outlook script (similar to the first but opens a different file). The below error message occurs while the first script is running through the Excel macros (in second file) and when you Debug, it highlights</p>
  
  <pre><code>Set OutApp = CreateObject("Outlook.Application")
  </code></pre>
  
  <p>This error doesn't happen when these two email triggered Outlook scripts are spaced out enough to let everything finish. So I know that the two scripts work when separately run (and I have tested this). </p>
  
  <p>Does anyone have any idea what could be causing this to happen? Can two email rules that trigger scripts run simultaneously if one of them is currently working in Excel?</p>
  
  <p><a href="https://i.stack.imgur.com/WN9yk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WN9yk.png" alt="enter image description here"></a></p>