excel vba - Vba code to Check file is the readonly -
please advise how check if file ready before opening it...
below code used open file...
myfilenamedir = "h:\shaikh_gaus\scratch\vba\book16.xlsx" workbooks.open filename:=myfilenamedir, updatelinks:=0 set ws1 = worksheets("students")
ways check or change attributes:
option explicit sub testfileattributes() const file_name string = "c:\test.txt" if isreadonly(file_name) msgbox "file read-only" if isopenasreadonly msgbox "file open read-only" makereadwrite file_name if not isreadonly(file_name) msgbox "file not read-only" end sub
.
public function isreadonly(byval fname string) boolean 'vbnormal = 0, vbreadonly = 1, vbhidden = 2, vbdirectory = 16 if len(fname) > 0 isreadonly = getattr(fname) , vbreadonly end function
.
public function isopenasreadonly(optional byref wb workbook = nothing) boolean if wb nothing set wb = activeworkbook isopenasreadonly = wb.readonly 'opened read-only within microsoft excel end function
.
public sub makereadwrite(byval fname string) const read_only = 1 dim fso object, fsofile object set fso = createobject("scripting.filesystemobject") set fsofile = fso.getfile(fname) fsofile if .attributes , read_only .attributes = .attributes xor read_only end end sub
Comments
Post a Comment