The process cannot access the file because it is being used by another process

Hello,
I was trying to implement an example with Excel triggers. However, every time Excel file is modified and saved UIPath throws an exception:

Monitor_Excel has thrown an exception

Message: The process cannot access the file ‘[local path]\invoice-template.xlsx’ because it is being used by another process.

Source: Read total value

Exception Type: IOException

System.IO.IOException: The process cannot access the file ‘[local path]\invoice-template.xlsx’ because it is being used by another process.
at UiPath.Core.Activities.MonitorEvents.BodyFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.FaultWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

Any ideas what causes this?..

1 Like

hi Elvis

the attached workflow has 2 validation errors, some lost space characters in two activities.
you will notice them when validating using the Studio`s option. If you fix those, the workflow will run just fine.
make sure you have excel package installed.

@Elvis

Usually it will come when you have opened that Excel which have written in WriteRange …

Plz add that xaml to identify the error…

1 Like

File change.zip (16.5 KB)

Hello,
thank you for the reply. I’ve attached all files. Any ideas on how to solve this?..

Calling below in your finally block of try catch method might help resolve the issue, unless you are missing something in the code.

7 Likes

Thank you for the reply, but this didn’t help. The file still can’t be accessed:

Monitor_Excel has thrown an exception

Message: The process cannot access the file ‘C:\Users\user\Documents\UiPath\File change\invoice-template.xlsx’ because it is being used by another process.

Source: Private: Read total value

Exception Type: IOException

System.IO.IOException: The process cannot access the file ‘C:\Users\user\Documents\UiPath\File change\invoice-template.xlsx’ because it is being used by another process.
at UiPath.Core.Activities.MonitorEvents.BodyFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.FaultWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

Please share your xaml.

Please check the message above, I’ve put all files in .zip archive.

I have modified the code, can you try and let me know if it works.

File change.zip (17.2 KB)

4 Likes

Hello and thank you for your inquiry.

first of all I guess you need to redefine the process because you are trying to get information from an excel template while it’s being process…(obviiously the reason for the error XD)

So, I see two approcheas here, one is to save the workbook and continue or to ask the user to close it. Like I said you need to define your automation in the way that will achieve what your customer wants to achieve.

For the ones intriguing about System.GC this and this article might be helpful

and here it’s the XAML xlalreadyopen.zip (51.2 KB)

:slight_smile:

3 Likes

I have kept a while loop where the robot keeps checking until the error has vanished ( you can send alert here) and in finally used GC method which I assume should work for him.

Refer my code if you want to.

4 Likes

@vvaidya Awesome, I like your approach for this automation. keep up!!! :sunglasses:

2 Likes

Works perfectly, thank you very much!
I believe someone should ping UIPath to update their knowledge base article on Excel triggers with your solution.

Thank you once more for your help!

@docteam

1 Like