Read Only Enforcement

  • Thread starter Thread starter andycharger
  • Start date Start date
A

andycharger

Is there a way in a macro to force read only?

I see that you can set readonlyRecommended=True.

However, when my users open up the file, they still have the ability t
open it as normal if they select it with the warning.

What I want to do if force my file to save in readonly and not let the
open it any other way.

Is there a way to do this when saving the file in the macro before
give it to my staff
 
Try setting the file attribute to read-only, this way
Excel will open as read-only without asking.
This is an operating system level attribute so potentially
could be changed outside of Excel.

In VBA use......
SetAttr "file", vbReadOnly

Since you presumably do not want your staff to change the
contents you might want to prevent "saving" this file as
well by disabling the save menu options.
 
I think you have to set the password on the options when
you first save the file (keep the password simple, and
keep a record somewhere)
 
Application.DisplayAlerts = False
ThisWorkbook.SaveAs ThisWorkbook.FullName, , , "sesame"
Application.DisplayAlerts = True

should do it.

The user would need the password ("sesame") to override the read-only
requirement.
 
Can you tell me how I disable the Save option in the menu then?
I need to do this either before or during the save of the document
Obviously I dont want to make it part of a macro that runs when a use
opens the file as they can choose to disable macros!

Also you mention the set attr function. Where do I set it and what do
type?


Any ideas
 
Andy,
The workbook has a _BeforeSave event, with a Cancel parameter.
That might do the trick.

Password protect the VBA code also, so it cannot be bypassed.

Anyone can still Copy the sheet to a new workbook though, by right clicking
on the sheet tab, so you would need to Hide sheet tabs form the Options and
protect the worksheet also.

NickHK
 
Back
Top