I have a Windows forms application that runs an excel macro using Office Interop. I run the macro from the main GUI thread but the macro is pretty long to run and after several minutes it ends up in an exception RPC_E_SYS_CALL_FAILED.
Any ideas?
Exception is : System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED))
My code :
// Excel Objects
Excel.Application xlApp = null;
Excel.Workbook xlWorkBookMacro = null;
Excel.Workbook xlWorkBookBilan = null;
try
{
// Open Excel
xlApp = new Microsoft.Office.Interop.Excel.Application();
// Open Workbooks
xlWorkBookMacro = xlApp.Workbooks.Open(Properties.Settings.Default.PathToMacroBilan);
xlWorkBookBilan = xlApp.Workbooks.Open(Path.Combine(Folder, Filename));
// Run Macro
xlApp.Run(MacroName, Filename, DateBilan.AddHours(HEURE_DEBUT_BILAN).ToString("dd/MM/yyyy HH:mm:ss"), int.Parse(ScheduleRec["no_batch"].ToString()), int.Parse(ScheduleRec["no_oper"].ToString()), int.Parse(ScheduleRec["type_activ"].ToString()), Path.Combine(RepertoireEnrSous, EnrSous), ScheduleRec["edition"].ToString(), ScheduleRec["imprimante"].ToString(), ScheduleRec["orientation"].ToString());
// Close Workbooks
xlWorkBookBilan.Close(true);
xlWorkBookMacro.Close(false);
// Close Excel
xlApp.Quit();
// Clean Excel Objects
ReleaseExcelObject(xlApp);
ReleaseExcelObject(xlWorkBookBilan);
ReleaseExcelObject(xlWorkBookMacro);
}
catch (Exception ex)
{
TraceLogger.WriteLog(String.Format("Exception : {0}", ex.Message));
}
I finally found a solution in adding a DoEvents in the main loop of my macro.
User contributions licensed under CC BY-SA 3.0