I have created a C# WinForms project which calculates numerical values and writes them to an open Excel spreadsheet. The program works by allowing the user to open a spreadsheet in the Excel program. The writing is carried out by one method called private void updateExcel_Click(object sender, EventArgs e)
which writes like so:
if (*in range*)
MySheet.Cells[activeRow, activeColumn].Value = total;
This approach works like a charm, except when there is an unsubmitted change made in the. By unsubmitted change I mean when the user goes directly into the spreadsheet and changes the number in the active cell without finalizing the change with one of:
When I write to the affected cell once more with the program I get a System.Runtime.InteropServices.COMException error. The full text being:
Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Dynamic.dll An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Dynamic.dll Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))
Oddly enough, when the direct user change is finalized with one of the bulleted methods I get no error when I rewrite to the cell with the program. How do I remedy my program to avoid the COMException error?
I already tried following the msdn link: How to fix 'Call was rejected by callee' error. I called the C# method updateCell_Click from the space labeled "Insert your automation code here."
User contributions licensed under CC BY-SA 3.0