Unable to cast COM object of type 'System.__ComObject' to interface type

excel
activities
p_qa

#1

Scenario: Trying to execute macro in Excel Application Scope and an error appears. If I execute the macro manually it works. I searched in other topics for a solution and I couldn’t find one.

Cadences has thrown an exception

Message: Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘Microsoft.Office.Interop.Excel._Workbook’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{000208DA-0000-0000-C000-000000000046}’ failed due to the following error: System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED)).

Source: Execute macro

Exception Type: InvalidCastException

System.InvalidCastException: Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘Microsoft.Office.Interop.Excel._Workbook’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{000208DA-0000-0000-C000-000000000046}’ failed due to the following error: System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED)).
at UiPath.Excel.Activities.ExecuteMacro.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

Steps to reproduce: In Excel Application Scope use Execute macro and run the flow.

Current Behavior: Exception thrown: InvalidCastException

Expected Behavior: To run macro successfully as before.

Studio/Robot/Orchestrator Version: 2016.6274

Last stable behavior: Worflow execution successfully run the macro.
Last stable version: 2016.6274
OS Version: Windows 7 Enterprise 64-bit
Others if Relevant: (workflow, logs, .net version, service pack, etc):

Noticed that having the “.xlsm” file in another folder location doesn’t bring any errors.

Eroare Macro


#2

The issue occurred.
Have you solved this issue?
If so, could you share the solution?


#3

Hello,

I couldn’t solve this. I think it is from excel registry.
Sometimes the error is not shown…


Getting Exception Type : InvalidCastException
#4

In my case, I included “workbooks.close” which kills EXCEL workbook which includes execute macro activity.
It means self-killing, that’s why this error occurred.
After I removed “workbooks.close”, this issued was solved.


#5

Hi Daniel,

Were you able to find a solution to this problem? I am facing the same issue. And an office repair / office re-installation didn’t help me.
Kindly let me know.

Regards,
Rajni


#6

Hi @Rajni3,

Not quite, I have a workaround:

-Open the macroEnabledExcelFile with Run command by using SendHotkey and TypeInto;
-Open MacroWindow in Excel by using Send hotkey and DoubleClick on MacroName;
-Used OnElementAppear to check when macroExecution has ended;
-Save Excel using SendHotkey;
-Close Excel…

I hope this helps you.

Regards,
Daniel


#7

Okay, so basically that would be executing the macro manually rather than the ExecuteMacro Activity. I will try that. Thanks.


#8

Hi Daniel,

I unchecked the Visible property of Excel Application Scope from which the ExecuteMacro Activity was being called. And it worked for me. The issue in my case was around the screen update during macro execution.

Regards,
Rajni