Copy Sheet activity throwing exception

Hi,

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.

18.3.1+Branch.master.Sha.4c05f670b311e90ee097c589605b399e9bee4874

Source: Copy Sheet

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)

Regards,
Pavani

Hi @pavani_gangireddy

We will definitely need more information about this issue. Please attach a sample project that has an issue:

  1. Create a blank project
  2. Add the minimum amount of activities that cause a crash
  3. Test if the crash happens
  4. Package the entire project and attach here on the forum

It will help a lot in debugging your issue :slight_smile:

What excel version are you using?

Hi @pavani_gangireddy,
You can achieve using invoke code just like am using invoke code to create pivot tables

Thanks & regards
Sanjay shankhla

I am facing the Similar issue

“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 ??

@aksh1yadav can you help around this ?

Hi @rahuls

Could you maybe post that sample project that recreated the issue? It would be nice to have to play around :slight_smile:

@loginerror Thank you for immediate reply !!

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!!

Thanks in Advance :slight_smile:

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:

Hey @rahuls

I am aware with this problem :slight_smile: and i can reproduce it and resolved it too :slight_smile: 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 :slight_smile:

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 :slight_smile:

Hope this helps you.

Regards…!!
Aksh

2 Likes

Thanks @aksh1yadav

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???

@badita can you throw some lights on this ??

as i am in still in development phase need to make sure my approach is right and wont cause problem in further.

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 :slight_smile:

2 posts were split to a new topic: Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED

The Excel Copy Sheet activity does not function properly with Office 2010 and 2013 versions.

1 Like

I m getting a sheet "xxx" doesnt exist exception. The sheet Im trying to copy has a space in the name. Im using Excel 2016.

Hi @rchernysh,

Can you try this to copy the sheet?

Regards
Balamurugna.S

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

1 Like