25

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?

fat
  • 6,435
  • 5
  • 44
  • 70
Manoj Nayak
  • 2,449
  • 9
  • 31
  • 53

14 Answers14

28

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.

Crash5998
  • 336
  • 5
  • 12
  • 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 [so]. – Bleeding Fingers Feb 19 '14 at 21:55
  • @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. – Crash5998 Feb 25 '14 at 00:06
  • 2
    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. – David Waterworth Feb 26 '14 at 02:31
  • 1
    Sadly this does not apply to all cases. My Excel is registered and I'm getting the said error. – Leo Gurdian Feb 25 '21 at 07:06
17

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.

Diego Montania
  • 322
  • 5
  • 12
Joost
  • 1,126
  • 1
  • 10
  • 19
6

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.

CJBS
  • 15,147
  • 6
  • 86
  • 135
  • Yes, thanks, some of my [DocxManager](https://docxmanager.com) (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. – Edwin Yip Dec 12 '19 at 15:28
  • 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. – Arrow_Raider Jun 01 '20 at 16:17
  • @Arrow_Raider - 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. – CJBS Jun 01 '20 at 19:03
  • 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 http://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. – Mitch Jun 22 '20 at 20:13
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.

Elmue
  • 7,602
  • 3
  • 47
  • 57
Alielson Piffer
  • 343
  • 2
  • 10
  • 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?". – Elmue Jun 12 '17 at 22:43
  • Yeah! I think that was exactly the problem, @Elmue. Though, for Excel must be XLSX files. :) – Alielson Piffer Jun 13 '17 at 14:46
  • You are right. The question is about Excel, not Word. – Elmue Jun 15 '17 at 00:41
  • 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! :D – Alielson Piffer Jun 21 '17 at 15:45
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.

amadib
  • 868
  • 14
  • 33
  • 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. – Elmue Jun 15 '17 at 00:29
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.

Duphorn
  • 29
  • 1
  • 2
    This answer is nonsense. It is absolutely no problem to work with multiple worksheets in Excel automation. – Elmue Jun 12 '17 at 22:40
  • 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. – budul Jan 21 '22 at 01:25
2

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.

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.

Ritzies
  • 33
  • 1
  • 7
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

1

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.

Martin H.
  • 133
  • 3
  • 8
1

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.

Pavel
  • 11
  • 1
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.

M H
  • 325
  • 3
  • 8
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

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.

Uttam
  • 596
  • 1
  • 6
  • 11