Hello,
Anyone knows how to detect an excel file is read only or not.
Thanks,
Detect read only Excel file
Moderators: Dorian (MJT support), JRL
Here's one way. Set vFile to your excel file or any other file path and name. The script uses the DOS attrib function to write vFile's attributes to a file. Read the file and parse it to see if the "R" (read only) attribute exists.
Code: Select all
Let>vFile=c:\path\filename
Let>RP_Wait=1
Let>RP_Windowmode=0
RunProgram>cmd /c attrib "%vFile%" > %temp_dir%checkmyfileattributes.txt
ReadFile>%temp_dir%checkmyfileattributes.txt,vData
DeleteFile>%temp_dir%checkmyfileattributes.txt
StringReplace>vData,vFile,,vData
Separate>vData,R,ReadOnlyTest
If>ReadOnlyTest_count>1
mdl>%vFile% is a read only file
Else
mdl>%vFile% is NOT a read only file
EndIf
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
I think the question is unclear. Does it mean an Excel file which has been set as read only in windows, in which case JRL's OS level solution is good, or does it mean an Excel file that has been set to open as read only in Excel in which case the file is not flagged as read only by the operating system?
- CyberCitizen
- Automation Wizard
- Posts: 721
- Joined: Sun Jun 20, 2004 7:06 am
- Location: Adelaide, South Australia
Goes to show what I know. Didn't know that an Excel file could be set to be read only only via Excel. What a concept. Doesn't make me like Excel any better.Me_again wrote:I think the question is unclear. Does it mean an Excel file which has been set as read only in windows, in which case JRL's OS level solution is good, or does it mean an Excel file that has been set to open as read only in Excel in which case the file is not flagged as read only by the operating system?