My Excel File has this attribute ticked, which I want.
Therefore it opens read-only. This file occasionally needs editing and saving.
It would be nice to have a macro(1) that could be run (when the file is open as Read-only) which switched to Write Access, in situ.
I would then make the changes and run macro(2) which makes it Read-only again.
This way I don't have to uncheck the property attributes before going into edit because sometimes you don't even know if you're going to have to edit.
You could use a routine like this:
Sub MakeReadOnly(sFile As String, Optional bReadOnly As Boolean = True)
SetAttr sFile, IIf(bReadOnly, vbReadOnly, vbNormal)
End Sub
called like this to make it read only:
MakeReadOnly "C:\blah.xlsx"
and to clear the read-only:
MakeReadOnly "C:\blah.xlsx", False
Ideally, you'd swap the bits so you didn't affect other attributes but this should do here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.