Excel Modern Activity-get sheet

Good day,
I have studio 2025, and would like to use modern activities to check if the sheet name exists in the excel file. I have some activities I have used for it but the issue is excel stays open then when it gets to Read range activity it errors because of that open file. Is there a way to check for an existing sheet and also to write onto the excel file column in the background..

These are the activities used:



@Anelisa_Bolosha1
Hi, If your excel remains open after getting sheets, You can Kill Process activity to kill the excel process. It will close it and you can read it.

Hi @Anelisa_Bolosha1

Yes, you can simplify it with Modern Excel activities:

Excel File → Check if Sheet Exists → If True → Read Range

Keep the sheet name in a variable, e.g. sheetName = “Fail”, and check it before reading.

This avoids the older Get Workbook Sheet approach.

Hi @Anelisa_Bolosha1 ,
The issue is likely happening because Excel remains attached/open within the Excel Application Scope, so when another activity tries to access the same file, it may encounter a lock.
Try the below steps:

  1. Use Use Excel File activity instead of Excel Application Scope.
  2. Get all sheet names using Get Workbook Sheets.
  3. Check whether the sheet exists:
    sheetNames.Contains(“Fail”)
  4. If the sheet exists, use Read Range and Write Range/Write Cell inside the same Use Excel File container.
  5. Enable Visible = False (or disable opening Excel) to work in the background.

Thanks

Hi @Anelisa_Bolosha1

The Get Workbook Sheets activity is unfortunately not developed as a Modern activity.

You can use the For Each Excel Sheet to loop the sheets and an If activity to check for your condition.

Regards
Soren

Hi @Anelisa_Bolosha1,

You can surround the Read Range activity with a Try Catch block. In the Catch block, handle the System.ArgumentException and check the exception message, which will indicate that the sheet does not exist.

This way, you can handle the missing sheet scenario gracefully instead of letting the workflow fail.

Thanks!

Hi Anelisa_Bolosha1

I think that the issue is that you use an Excel Application Scope which opens the file, then down further down the process you use a Read Range activity that is not meant for the Excel Application Scope. It tries to open the file again - which it can’t because it is already open.

If you in the Activities list in Studio Search for ‘Read Range’ then you should find at least two ‘Read Range’-activities. You should use the on where you don’t have to give the filepath again.

The correct Read Range will not need a filepath because you already gave it in the Excel Application Scope.

Hope this makes sense and helps.
I can make you an example if you need

Can you please give examples of activity on this

I’m using the latest UiPath studio, do I still need to use application scope?

I you don’t know the name of the sheet I would say yes you need the scope, I guess it would be possible to make a script to handle it. But out off my knowledge scope :slight_smile:

I have added the code that I took a picture of earlier.
You can also finde the code here: GitHub - AutomationGems/UiPath-Forum-Examples: Examples used for UiPath answers · GitHub

Read Sheet from Excel.zip (1.0 MB)

Oh, I had this already :slight_smile: thank you so much. The sheet name can be like:
“Fail” or with a space - "Fail ". It can be in position 1 or sometimes 2 ,how do I achieve this…

Okay, then I would use the Get Sheets activity instead, it gets all the sheets in the excel. Then I would look in that array of sheetnames after one named ‘Fail’.

I have attached example and also pushed to github :slight_smile:

Read Sheet from Excel.zip (1.0 MB)

Does the heart mean it works?

If yes please mark as solution :slight_smile: If not please let me know

Hi thank you for this, the issue with the index is that it changes

Not yet please see the workflow, I tried using the solution attached but it goes to the else part"..This starts here to check if there is a file first of all:–
![image|422x500]

On the else side there is :




Okay, I think I made the condition in the if quite “strict”, could you try this instead:
arrSheets.Any(Function(x) x.ToLower.Trim.Contains(“fail”))

I replaced the ‘Equals’ with ‘Contains’, which was what you also had in the original post.

I have done so it still goes to the else part

Hi again

In the second picture i see that the variable called ‘SearchFile’ is used in the For Each as an array/list of files, but the same variable is used in the Excel Application Scope as a single file.
That seems wrong, In the properties pane of the ‘For Each’ you should be able to se the variable name for each item in the array/list of file (I think default is currentText or something similiar), that should be used in the Excel Application Scope.

Could you check that?

Hi @Anelisa_Bolosha1,

I think @MrBidstrup’s point about the For Each variable is worth checking.

If SearchFile contains the list/array of files, then inside the For Each you should use the current item variable as the Excel file path, rather than using SearchFile itself.

For example:

For Each filePath In SearchFile

Then in Use Excel File / Excel Application Scope → File path, use:

filePath.ToString

For checking whether the filename contains “fail”, you can use:

SearchFile.Any(Function(x) x.ToString.Trim.ToLower.Contains(“fail”))

Or, if you want to check the current file inside the For Each:

filePath.ToString.Trim.ToLower.Contains(“fail”)

Also, I would suggest adding a Log Message before the If condition:

String.Join(", ", SearchFile.Select(Function(x) x.ToString))

This will help confirm whether the expected files are actually being returned. If the log shows the file but the condition is still going to Else, then we can narrow down the issue with the variable type or file path.

Hi thank you, I am using this function for checking if that sheet does exist amongst the 3 and even if it doesn’t as long as there is a word ‘Fail’

But I am getting that error ‘WorksheetquickHandle’