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

15

26

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?

Cosimo answered 11/12, 2013 at 8:51 Comment(4)
did you try with: ... = new Excel.Application();??Menarche
Are you using .Activate or .Select anywhere? Which line gives you the error?Flavorous
I need ApplicationClass to run macro in destination excel. ApplicationClass and Application are same?Cosimo
No I didn't use any such things.. The error is coming while getting all worksheets in the excel i.e. excelSheets = _destExcelWorkbook.Worksheets;Cosimo
B
29

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.

Butterfingers answered 19/2, 2014 at 21:33 Comment(4)
So you're suggesting that the exception is being raised because of unactivated and unlicensed Excel and that activating it would fix that issue. Sounds odd. Btw welcome to Stack Overflow.Rosenquist
@BleedingFingers, yes. I ran into a situation where this exception was thrown, and another function of my application threw a separate error relating to "reduced functionality mode." Re-installation and activation of Excel resolved both issues.Butterfingers
I've been experiencing the same issue with an unactivated version of Excel. I think in general it's caused by Excel being busy at the time you invoke it - that could be because it's attempting to show a dialogue warning that you don't have a valid license, or maybe you're attempting to open a spreadsheet with links and the linked spreadsheet isn't available etc. I think in general the solution is to implement IMessageFilter as mentioned above (I've not tried this yet). I've worked around it by opening spreadsheets readonly, with links disabled etc.Stradivari
Sadly this does not apply to all cases. My Excel is registered and I'm getting the said error.Corliss
F
19

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.

Fiesole answered 10/1, 2019 at 10:13 Comment(0)
B
7

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.

Bouleversement answered 9/1, 2018 at 0:7 Comment(4)
Yes, thanks, some of my DocxManager (document manager for MS Word with tags, tabs, etc) users reported the Call was rejected by callee error in such situations. This should be the root of such issue, not that Word's not the default program as described in another answer.Elate
This is happening to me in Windows 10. When I click Yes, it just tells me I have to do it myself in Settings. I don't know which extensions besides doc and docx it wants. This is stupid.Aleece
@Aleece - it doesn't matter what the configuration is; what matters is that the dialog doesn't show (because it interferes with the automation). When the dialog appears, regardless of your response, make sure to select "Don't show this message again", then it won't block future automated launches of MSWord.Bouleversement
I was able to get around this error by opening the program (MS Project 2013 in my case) as the local system account (since that is the user of the service) and going through the default program setting dialogs and then closing it. To open it as the local system account I used technet.microsoft.com/en-us/sysinternals/bb897553 and opened a command prompt (as administrator) and then issued this command: psexec -s -i "C:\Program Files (x86)\Microsoft Office\root\Office15\WINPROJ.EXE" The executable will be whatever program is the problem.Inflammable
A
5

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.

Affiche answered 5/6, 2017 at 14:55 Comment(4)
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?".Ballman
Yeah! I think that was exactly the problem, @Elmue. Though, for Excel must be XLSX files. :)Affiche
You are right. The question is about Excel, not Word.Ballman
Actually, my problem happened when I was working with a Word file. But since the problem appear to be the same for Office files, I agree it would be easier if I just say about Excel instead. Thanks for the help, @Elmue! :DAffiche
T
3

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.

Transaction answered 12/5, 2015 at 11:10 Comment(1)
Probably you did not analyze this problem thoroughly. OpenOffice neither depends on DLLs from Microsoft Office nor vice versa. So your conclusion with a DLL conflict is surely wrong. What happend probably is that Excel asked you if you want to open XLSX files with Microsoft Excel because your default program for XLSX files was OpenOffice. See the answer from Alielson Piffer who solved this problem without unstalling OpenOffice. Whenever Excel opens a popup at startup you may get error RPC_E_CALL_REJECTED or VBA_E_IGNORE or DISP_E_EXCEPTION.Ballman
M
3

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.

Mussorgsky answered 13/11, 2018 at 18:14 Comment(0)
E
2

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.

Elliott answered 11/12, 2013 at 16:50 Comment(2)
This answer is nonsense. It is absolutely no problem to work with multiple worksheets in Excel automation.Ballman
I have had a similar issue using an Excel.Sheets collection in an asynchronous method. But the issue has not appeared always but rather nondeterministically. After changing the method into a synchronous approach, the problem has not appeared anymore.Bigamous
M
2

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.

Mehetabel answered 6/2, 2018 at 12:33 Comment(1)
Same problem with Add-Ins in Excel 365 - 32 bits. I disabled all Add-Ins in Excel and my Power Automate Desktop has no more issues related to HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)Arillode
S
2

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

Smorgasbord answered 5/4, 2019 at 18:51 Comment(0)
L
2

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

Lashundalasker answered 26/2, 2020 at 6:6 Comment(0)
T
0

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.

Tightlipped answered 5/6, 2020 at 7:13 Comment(0)
B
0

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

Beamy answered 12/6, 2020 at 6:59 Comment(1)
Please clean up your suggestion; it's really hard to follow what you're saying.Corliss
S
0

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.

Sallysallyann answered 15/1, 2021 at 12:53 Comment(0)
G
0

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.

Genethlialogy answered 20/8, 2023 at 8:25 Comment(0)
B
0

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.

Basketball answered 23/12, 2023 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.