Properties: Attributes "Read only" vs."Archive"


Posted by Jim on December 27, 2001 7:35 AM

Hi group,

Is it possible to hard code the Attributes to "Read only"
in other words the the file would always have to be saved
as another name and the original would stay intact.

This would not allow anyone to change the attributes
in the properties before opening the file from
"Read only" to "Archive"

Thanks, Jim

Posted by Joe Was on December 27, 2001 9:02 AM

This is the code to set or un-set the Read Only bit.

Sub SetReadOnlyBit(filespec)
Dim fs, f, r
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(fs.GetFileName(filespec))
'Note: "1" is the Read Only code!
If f.Attributes And 1 Then
r = MsgBox("The Read Only bit is set, do you want to clear it?", vbYesNo, "Set/Clear Read Only Bit")
If r = vbYes Then
f.Attributes = f.Attributes - 1
MsgBox "Read Only bit is cleared."
Else
MsgBox "Read Only bit remains set."
End If
Else
r = MsgBox("The Read Only bit is not set. Do you want to set it?", vbYesNo, "Set/Clear Read Only Bit")
If r = vbYes Then
f.Attributes = f.Attributes + 1
MsgBox "Read Only bit is set."
Else
MsgBox "Read Only bit remains clear."
End If
End If
End Sub

Hope this helps you. JSW

Posted by Jim on December 27, 2001 9:13 AM

Re: Properties "a question"

Hi Joe

Thanks for the help, one question, where do i put
the code in Workbook_BeforeClose?

Jim



Posted by Juan Pablo G. on December 27, 2001 9:50 AM

Re: Properties "a question"

In the module named ThisBook.

I have another suggestion. When you do a saveas, click options, and set a password for "Write". Because you could change the properties using Explorer and then open it as a normal file, even though the code had run the last time, setting it to read only.

Juan Pablo G. Hi Joe Thanks for the help, one question, where do i put