Error Executing Macro. Unable to cast COM

excel
activities

#1

Scenario: Trying to execute a macro in a excel aplication scope. To execute this macro i need to have open another 2 excel files. Doing this manual it works just fine. Note that it takes a while to finish running the macro (in manual execution).

Steps to reproduce: You need my files to reproduce. Using 3 excel files in excel application scopes and execute macro.

Current Behavior: Macro runs and after some time it throw’s the following error: Execute macro : 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: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)).

Expected Behavior: To execute macro and wait untill it is finished. (it takes a long time to execute due to large data inside excel file).

Studio/Robot/Orchestrator Version: 2016.6442

Last stable behavior: no stable behavior
Last stable version: 2016.6442
OS Version: Windows 7 Enterprise
Others if Relevant: (workflow, logs, .net version, service pack, etc):I have this problem with another macro that takes some time to execute. I get the same error message.

I have posted in another topic and no one helped me. I even talked to a UiPath employee and couldn’t give me a solution.


#2

Hey,

You should check if the macro has the following instruction in it:
Application.Quit

I have had a similar issue with a macro execution activity, and after a thorough inspection as to why the exception is thrown, I found out that if I delete the previously mentioned code line from the macro, the activity works flawless.

Try removing it or finding a work-around if you really need that line.
Hope this helps!