Getting an error while passing Excel object from one sequence to another

I am trying to pass workbook instance from one sequence to another. it is working fine is its normal sheet (Read and write operation). Moreover if the excel has add-in control or ActiveX control then it throws and error. Below is there error:

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 RPC server is unavailable. (Exception from HRESULT: 0x800706BA).\r\n at UiPath.Excel.Activities.InvokeVBA.EndExecute(AsyncCodeActivityContext context

Hi @manishsoni0407

Try going to options in excel and enable macros and disable external links or activex and all from the trust centre may be they are causing issue. And if you are trying to use macro then try with setting excel to visible .

Cheers

The option of Macro is already enable however disable Activex control is not an option as we need to perform an operation on those control. and we have use Invoke Vb code for the same.
and also same code is working fine if the excel object is created in same sequence. but when i pass it to different sequence then the problem arise.

Hi @manishsoni0407

Are you trying to keep the excel open …?

Cheers

Yes , Here is my screenshot
Arguement :

Object property

Error:


Sequence1.xaml (7.0 KB)
Sequence.xaml (10.5 KB)

Hi @manishsoni0407

Dont open you excel and invoke instead move invoke out of excel then in your inner flow open your excel and pass it back here.

If passing is not working then in your inside workflow let the excel close after the task and then reopen it in the main workflow again

Cheers

Hi @manishsoni0407

I see one more thing here in your inner workflow pass the wb variable both in existing and the output fields .that might shed some light.check my previous comment as well

cheers

We have to do it in this way only the reason is at some place i need to perform an operation in Activex control . So we have used Invoke VB code , which will only work when it is inside Excel scope. Now the requirement is, there are 100 of controls and we need to perform and operations on those controls. So there is inner sequence and there is one main sequence that’s why i am doing it like this

Hi @manishsoni0407

I agree with your point, but what i see is the first thing that you do in the excel scope as per screenshot is invoke what i am saying is move that invoke outside as inside invoke you would already have had an excel acope qhich will take care of whatever steps that you do there and pass it out and use excel acope again the same way

Cheers

Thanks Anil ,
I have created a sample, however it is not the actual representation. Here is how we have implemented it.

ExcelApplicationScope

  • Try for Control 1
    Invoke Vb Code

  • Catch
    Invoke VbScriptRetry

  • Try For Control 2
    Invoke Vb Code

  • Catch
    Invoke VbScriptRetry

For Reference i have included actual code
VBScriptRetry.xaml (24.8 KB)

PopulateCensusGenerationChecklist.xaml (685.4 KB)

the problem , i have observed is excel is getting closed out of sudden within excel scope. Not sure why.

Hi - apologies for getting to this quite late.

What is the reasoning for passing the workbook as an argument to another workflow? Would it be possible to only pass the file path and open it within an Excel Application Scope in a different workflow?

Thanks,
Raluca

If you observe the structure , there are 100 of Activex control with we need to perform an action based on certain condition. However we try it for the first time and if its fail we retry it in catch block. We instead of writing a separate block in each catch we have written common sequence and pass the Excel object and control name. As it execute the different sequence in catch block and then we need to resume on main flow for rest of the control.
Sending an Excel path is not an option because we don’t know when the failure occurred and it will go to catch block. As we need to work on different control on same excel and same sheet.

Hi @manishsoni0407 ,

I’ve filed this on our side for our engineers to investigate this further. I’ll follow up here once we have any updates.

Many thanks,
Raluca