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

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

1 Like

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

Hello,

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

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.

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

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

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

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

6 Likes

Damn, this worked for me! Many thanks!

It’s kinda weird though.

Anyways, bless you dude

1 Like

I have faced with this case. Although I unchecked the Visible property, it’s still didn’t work.
Then I tried to let screen updating = false in my vba code. It’s solved.
Hope it help some one if they got similar sistuation.

1 Like

Also VBA scripts fail with Autosave option of Excel Scope is disabled

hello,

is your excel application 64x ?

thanks man!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.