Detect if an Excel file is read-only

Hi guys !
I found different topics concerning this question, but none have been solved.
I would like to detect if my excel file is read-only, is it possible ? And in the case the read-only button is checked is it possible to uncheck it ?

I found this answer on another topic but I don’t understand it :
" You can build in a check for it with ‘Element Exists’. As a selector make sure that the ‘Read Only’ part is in the name of the window.
For example, use the following selector: <wnd app=‘excel.exe’ cls=‘XLMAIN’ title=‘Excel Sheet - Read-Only*’ />
‘Element Exists’ will only return ‘true’ if Read-Only is in the name of the file. If it does, you can handle it as you wish."

Can you help me with this please ?

Thank you !

if excel is opened in read-only mode then this is marked on the title. So the mentioned strategy was looking for this token to decide the open mode

Ok ! Thanks ! I didn’t notice that it was written automatically in the tittle … ^^

I have some problem to use the formula in my project …

In my project, the user has to enter the name of the Excel file we want to work on. For example :

PATH = "C:\Desktop\Excel_file.xlsx"

So I do :

File_Name = Path.GetFileName(PATH)

and I modify the formula like this :

<wnd app=‘excel.exe’ cls=‘ + PATH + "’ title=‘ + File_Name +" - Read-Only*’ />

But that’s not working because the File_Name I use doesn’t contain the “Read-Only” words.
So how can I do to directly get the name of the opened file with the “Read-Only” words ?

I would suggest to explore what excel is adding for a read only open in your language. I guess it is French, right?

Yes I know. The only difference in French is that “Read-Only” is replace by “Lecture Seule”.
But that’s not working …

@Camille361
try one thing:
Use variables in selectors as described here:

the benedfit is, that with a default value the selector can be validated along the dynamic part

Remove the cls from selector cls=’+ PATH+’

wnd app=‘excel.exe’ title=‘*{{FileName}}*Read-Only*’ />

1 Like

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