1

I have a process that is opening multiple workbooks

var exApp = new Excel.Application(); 
Excel.Workbook ONE;
Excel.Workbook TWO;
Excel.Workbook THREE;
ONE = exApp.Workbooks.Open(ONELocation);
TWO = exApp.Workbooks.Open(TWOLocation);
THREE = exApp.Workbooks.Open(THREELocation);
Console.WriteLine("All Excel workbooks opened successfully\n");

Sometimes it runs with no issues.

Sometimes though I get the following exception on crash

System.Runtime.InteropServices.COMException: 'The remote procedure call failed. (Exception from HRESULT: 0x800706BE)'

The exception happens on different workbooks and sometimes not at all. When it happens after rerunning a few times the process goes through successfully and all data is processed correctly.

Why does it work sometimes and not others? Is there a better way to open these workbooks? How do I stop this from happening?

M Y
  • 1,831
  • 4
  • 24
  • 52
  • Your question is likely a duplicate of https://stackoverflow.com/questions/4471787/system-runtime-interopservices-comexception-0x800706be-when-getting-contact-la – xxbbcc Jun 19 '17 at 20:15
  • Possible duplicate of [System.Runtime.InteropServices.COMException (0x800706BE) when getting contact.LastName](https://stackoverflow.com/questions/4471787/system-runtime-interopservices-comexception-0x800706be-when-getting-contact-la) – xxbbcc Jun 19 '17 at 20:15

1 Answers1

1

RPC_S_CALL_FAILED was indeed the root cause as pointed out by the question user xxbbcc linked to as a possible duplicate.

However, that just told me the cause and did not solve the problem. I googled RPC_S_CALL_FAILED with the word excel and found this SuperUser question

I disabled the "FoxitReader PDF Creator COM Add-in" as described in the question and my program now runs consistently without error.

How to disable the plugin: Excel > File > Options > Add-ins > Manage, then choose "COM add-ins" > Go. And then untick the problematic plugin.

M Y
  • 1,831
  • 4
  • 24
  • 52