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..
@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 ,
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:
Use Use Excel File activity instead of Excel Application Scope.
Get all sheet names using Get Workbook Sheets.
Check whether the sheet exists:
sheetNames.Contains(“Fail”)
If the sheet exists, use Read Range and Write Range/Write Cell inside the same Use Excel File container.
Enable Visible = False (or disable opening Excel) to work in the background.
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.
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.
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
Oh, I had this already 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’.
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]
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.
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:
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.