How to prevent double opening of excel file?

we have two robots on two machines running (we don’t have an ochestrator). They both do their jobs and now we want them to write a new row in an excel spreadsheet, which job they did at which time and so on.
We would read the datatable from the excelfile with read range, add the new row and then write the datatable again as the excelfile with write range.
How can we prevent, that the two machines try to read or write at the same time and we get exceptions? Can we check the file, if it is used by an other process or machine?
Thank you for your help

1 Like

Hi @mm1904

yes it has using these codes.Check if a shared workbook is already open by another user

cheers :smiley:

Happy learning :smiley:


Hello @pattyricarte,
thank you for your answer.
How can I use this sort of code? That doesn’t look like UiPath, or is there a special place to write such code in UiPath?


1 Like

It is VB.NET and you can use Invoke code activity with that.
See this post Invoke code activity VB.Net example for how to use it.

1 Like

you can even add your file to share point or office 365 to do same time edit.

Hello @TimK,
I’m sorry, I’m all new to VB and in our corporate I have only limited possibiities to use the academy and youtube :hot_face:
I get a lot off errors when I try to invoke the code from the link (see pictures, sorry errormessage is in german), starting with unknown types ‘application’, ‘workbook’ etc.

Do I need some dependencies for VB or other things installed to the computer?
Thank you!

Hi @mm1904

Check this

How to open excel applicatiion using VB.NET?


The package isnt installed properly, @AshwinS2 has suggested correctly, more specifically the package isnt available. You see the post at the bottom of How to open excel applicatiion using VB.NET?

@mm1904 - i wouldn’t bother creating custom code or invoking c#/ code. This can be handled with a simple try-catch instead.

Workbook read or write range (NOT excel read range) will throw an error if the workbook specified is already open. Therefore, you can put it inside a try catch so it will try to update excel. If it is already open, it will throw an error and the catch loop can handle it however you choose

1 Like

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