"COM object that has been separated from its underlying RCW cannot be used" + Try Catch Issue


Screenshot 2
Hi Community,

I’m encountering an issue in a UiPath workflow where an Excel formatting action triggers the error: “COM object that has been separated from its underlying RCW cannot be used”. Despite reading other forum posts, I’m unclear about what this error specifically refers to and haven’t found a resolution. Does anyone know more about this error and how to handle it?

Additionally, I tried to manage the error with a Try Catch block, which unfortunately isn’t catching the exception, causing the workflow to fail. The workflow runs in picture-in-picture mode. Could someone help me understand why this might be happening?

If I simply remove the two Excel Format activities the workflow runs without error.

A redacted workflow is attached (with the confidential elements removed) and also screenshots of the try catch.

Thanks in advance for any help!

Mark
Workflow.zip (5.4 KB)

This happens when it tries to read an Excel file that you already have open, and it throws an exception, then you close the Excel and click the retry button (debug mode). Not sure if this is what’s happening to you, but maybe it’ll point you in the right direction.

1 Like

Thanks for your response @postwick . I confess that was my initial assumption however, I have tested it on a newly rebotted machine and therefore the Excel is only open due to UiPath opening it.

I have also tried as you suggested, closed the file and clicked retry but in this case I get an error saying UiPath has lost connection to the file (I can’t recall the exact error message).

I don’t suppose you have any comments on the Try Catch issue do you? At the very least I was hoping to resolve this issue through the Try Catch.

Thanks, Mark

Is your Try Catch inside the Use Excel File?

Do you have more than one Use Excel File?

I wasn’t recommending closing Excel, I was explaining that doing so can cause this error.

The Try Catch doesn’t resolve the issue, it just stops the exception from faulting the job. But the formats still won’t be applied. Can you show the whole Use Excel, at least up to the Format Cells activities?

Workflow.zip (5.4 KB)
Sure, workflow attached.

There are two excel files being used, one inside this one. That Excel file is closed in each cycle of the loop. What’s odd to me is data is written to the Excel document with no issues, it is the formatting immediately after that is causing the problem.

My Try Catch is inside the Use Excel (but not inside the other one). I wasn’t expecting the Try Catch to resolve the issue but handle the exception, which it isn’t, the exception is triggering the workflow to fail and is not reaching the exception handing element of the try catch.

My apologies regarding the closing of Excel. I have testing this a number of times, Excel remains open throughout the issue.

Thanks, Mark

Adding Screenshot of the workflow:

So you have a Use Excel File inside another Use Excel File? This is probably the issue:

This causes issues. I think what happens is the value of Excel gets overwritten by the sub Use Excel File activity, and then when it finishes and closes that file, the remaining activities in the parent Use Excel File are trying to access the file meant for the sub Use Excel File. Hope that makes sense. It aligns with what I said about getting this error when an activity tries to interact with an Excel file that has been closed.

You have to change one of them, but I’d change both of them so it’s easy to know which is which in your activities/expressions:

You’ve nailed it @postwick! Thanks so much.

Still an odd one of the TryCatch…

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