Detect read only Excel file

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Leevan
Newbie
Posts: 9
Joined: Sun Jan 27, 2013 4:09 pm

Detect read only Excel file

Post by Leevan » Tue Feb 05, 2013 11:06 pm

Hello,

Anyone knows how to detect an excel file is read only or not.

Thanks,

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Feb 05, 2013 11:29 pm

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

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Wed Feb 06, 2013 12:03 am

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?

Leevan
Newbie
Posts: 9
Joined: Sun Jan 27, 2013 4:09 pm

Post by Leevan » Wed Feb 06, 2013 12:34 am

Thanks,

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Wed Feb 06, 2013 1:14 am

In Regards To Me_again's Points, If Its Excel Opening The File In Read Only You Could Search For The Window Title To See If It Contacts The Words Read Only. They Are Normally Opened Something Like Resume [Read Only]
FIREFIGHTER

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Feb 06, 2013 2:13 pm

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?
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.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts