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.
... = new Excel.Application();
?? – Menarche.Activate
or.Select
anywhere? Which line gives you the error? – Flavorous