how to solve Exception:Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)) in C#?

126.9k views Asked by At

I have written a C# code in console application to open two excels and copy and paste data from one excel to another excel. It was working fine until the destination excel's visibility was true. But I need to hide the excel at the time of execution. So I changed the visibility to false. Like,

  _destExcelApp = new Excel.ApplicationClass();
  _destExcelApp.Visible = false;

Now its showing an exception like

Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))

How to solve this one?

15

There are 15 answers

4
Crash5998 On BEST ANSWER

I ran into this same error being thrown when I deployed my application onto a machine without a fully activated and licensed installation of Excel. I spent hours trying to diagnose the issue. Make sure you check your Office installations to make sure they are complete.

2
Duphorn On

Are you copying a range of information from one document to another, or are you going back and forth between the 2 documents copying cell by cell? Excel is single threaded, so if you go back and forth, it could cause this issue.

0
Ghostnine22 On

Ran into this problem on my machine. Excel is fully activated and already the default program for .xlsx files. I was loading a workbook template I created with pivot tables and having a script update the data in the tables. Turns out that if the pivot tables are set to "Refresh data when opening the file" under Pivot Table Options > Data, it causes some sort of threading contention issues.
Disabling the refresh on opening solved the issue.

4
CJBS On

Ensure that MS Word/Excel is not showing a dialog box that needs a response.

I set a breakpoint on the line that caused the failure, then set .Visible to true in PowerShell, to find this:

$word.Visible = $true

MS Word Set default program prompt

After I clicked 'Yes' and updated the settings, after I re-ran my scripted COM interactions, they succeeded.

0
M H On

I can offer another thing to look out for in addition to the solutions above, which seem to converge on this comment (on an answer by Alielson Piffer),

SUMMARY: So by the answers here we could conclude that this error may occur when Excel is showing any message in a popup window like for example "This software is not activated" or "Do you want Excel to be the default application for DOCX files?". – Elmue Jun 12 '17 at 22:43

There were no open messageboxes or prompts but there was an unended process (Word.exe in my case) in task manager that I needed to end. That fixed it.

This would explain why a restart helped another user.

1
Deepak Sharma On

Make sure you check your Office installations to make sure they are complete.

otherwise try following

try App visibleity false after the all Data is writin then turn on the Visibility ex Dim wapp As new excel.Application .... . . wapp.Visible = false

'do your writing .. . . . .

'then turn on your visibility

wapp.Visible = True

0
Joost On

I solved this behaviour with the help of this question:

Strange behaviour of "Call was rejected by callee." exception with Excel

The issue was simply that the Workbook.Open hadn't finished when I gave a Worksheet.SaveAs command. So sometimes, the script would work, sometimes not.

I simply added a pause in the script after Workbook.Open and it worked. I went on to find a property Ready, which allowed me to do exactly what I wanted:

$excel = New-Object -ComObject "Excel.Application" -ea Stop
$wb = $excel.Workbooks.Open($workbook)
$sheet = $wb.Sheets("List")
while (-not $excel.Ready) {
     sleep 1
}
$sheet.SaveAs($csvpath,6)

So in my case, it had nothing to do with non-activated or corrupted Excel installations.

0
Ritzies On

In my case, I simply restarted my machine and found out that there was a windows update pending. Restarting the machine solved my problem.

0
Pavel On

I have the same problem. I ran the program on "Windows XP x86" and it crashed with a similar error. The problem was in the line:

sheetSource.Cells(i, iColumn).Interior.Color = RGB(255, 255, 0)

Multiple executions of this line resulted in a crash. When I deleted it immediately everything started working fine.

0
user12964471 On

I agree with those that say excel license must be activated, I had the same problem and I activated the license everything works fine - Papiki

0
Joe Meyer On

I got the message at random places when reading an excel file that linked another workbook using microsoft.office.interop.excel. I was able to read the file without problems on the machine where I had initially set up the link but the same progran didn't work on a different machine. The link was perfectly fine and within excel all data from the linked workbook could be refreshed without problem but it gave me an error when reading the workbook programmatically. Unfortunately I haven't found a way to circumvent the error.

0
Uttam On

I was using PowerShell to create Excel object and run multiple linked tables and pivot refresh operations. I was randomly getting errors on the commands for different tables after a refresh operation or the pivot refresh operation. And one of such errors was:

Call was rejected by callee. (0x80010001 (RPC_E_CALL_REJECTED))

Setting the Excel Visible property to true stopped the errors, but I did not want the Excel window to be visible. I tried using Excel other properties - Ready, CalculationState to add pause, but did not solve the issue. Tried adding pause up to 10 seconds also (just to test), but still erros were there. If I tried manually, all refresh were completed in less than a second, so 10 second was a very long time but still it did not solve the issue, though it seemed to reduce the number of errors.

Finally I tried setting the ScreenUpdating property to true before refresh operations and set it back to false later. This solved the issue for me.

Sample PowerShell code ($xlapp is the variable for Excel COM Application object):

$xlapp.ScreenUpdating = $true
.
.<commands that cause issues>
.
$xlapp.ScreenUpdating = $false

Even though the Excel Visible property was set to false, setting ScreenUpdating to true helped and errors stopped.

1
amadib On

I ran into this issue with Word and my solution was uninstalling OpenOffice. I'm not sure if there's another solution but most likely has to do with the dlls and a conflict with the default file handler for the particular files you are generating programmatically.

4
Alielson Piffer On

I was facing the same error and many solutions suggested were not working for me. I had an application running in windows 8 and I found that the problem was Excel always asking to choose default application for "xlsx" extensions. When executing the application no window dialog appeared, just the error was shown.

I solved the problem going to Control Panel > Programs > Default Programs and setting Microsoft Office Excel 2016 as default program for xlsx files.

1
Martin H. On

I encountered this Error today in Excel 2016.

We found out that the computer with this problem had some add-ins activated.

Strangely that one pc took ages to start excel. after deactivating the add-ins our program worked fine.

Strangely we couldn´t reproduce this on our dev pc´s.