I’m using Copy Sheet activity to create a copy of an existing sheet in an excel. I used this activity in excel application scope and provided Sheet Name and Destination Sheet Name parameters. However, when I run the robot, I’m getting the following error. Please help.
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: The requested object does not exist. (Exception from HRESULT: 0x80010114).
Exception Type: System.InvalidCastException
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
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: The requested object does not exist. (Exception from HRESULT: 0x80010114).
at UiPath.Excel.Activities.ExcelInteropActivity`1.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)
“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)).”
Excel Package : 2.4.6863.30657
Workflow
1> Open and save Excel sheet 1 as workbook object as wbExcel1
2> Open second excel sheet and copy sheet to 1 st workbook
3> Open the wbExcel1 by excel app scope and just doing read cell or any simple activity will throw up this error.
Please note its successfully copy pasting the sheet but throwing an error in stage 3.
*** the same approach works with if i use workbook path instead of a excel object***
Facing this issue since last 2 days have created simple new workflow with temp excel files also does throw the same error.
is there some workaround for this using workbook object ??
Its just two dummy excel files , and 5 uipath activities as follows
1>Excel App Scope (Excel 1) o/p wbExcel1
2>Excel App Scope (Excel 2)
2.1> Copy sheet (copy a temp sheet from Excel1 to Excel2)
3>Excel App Scope (Excel 1) Input Existing workbook wbExcel1
3.1> Write Cell A1 : temp
#Just5 Steps
Sorry @loginerror i cant upload the flow here due to environment restrictions !! permit me some time will upload from different environment in some time.
By the time if you can workaround with above information that would be helpful!!
I have hard time reproducing it to fail, but I also found out that it might be related to the Copy Sheet activity. Do you happen to use Office 2010 or 2013? If you go to the documentation of this activity, there is a known bug related to it:
I am aware with this problem and i can reproduce it and resolved it too earlier.
Just For your Information
While using Copy Sheet Activity in In Second Excel Scope you are not passing any Destination File Path So By default as a behavior of Copy Sheet Activity
If this field is left empty, the sheet is copied in the current scope workbook
and current workbook Scope is having Excel Object of Second Excel. So it is raising a wrong Thread Error.
So to handle it you have to pass the first Excel Sheet Path or to make it dynamic use like
wbExcel1.CurrentWorkbook.FullName
after this change you won’t get that Exception.
So problem does not fully resolved here after this if you will again use Excel Application Scope with Existing Object then you will get Process has been Disconnected Error.
So to resolve this you have to use Path of Excel Here to instead of Excel Existing Object
Note - Do not use here File name with path using Excel Object because that object has been disposed so either after first Excel Application Scope Assign File path to a local variable and then use it in your last Excel Application Scope
Already started the way around and found out it works well with the path but sometimes causes an issue, so as per our discussion we shouldn’t use objects for Excel application scope instead we should actually read by workbook path only when using copy sheet activity.
Can someone from Uipath team actually give a confirmation that no matter what MS excel version being used if we are using workbook path for reading and doing operations in file it will work just fine ?? or it can create issue in future???
I have trouble reproducing this issue on Studio CE 2018.4.2 and Excel 2016. Could you post your project or a bunch of screenshots so that I can recreate it 1:1
Thank you, but I wanted to use the uiPath package and activities. I did find a workaround by copying the whole file and using a macro to delete pages that I don`t need