Re: Workbook Password Protect 2 Levels With 1 Pwrd
I believe that you cannot change the attribute of a file while it is opened. If I am not wrong, the VBA line "Workbook.ReadOnly" is used to test whether a workbook is set as Read-Only before it is opened.
I suggested using the following:
Private Sub Workbook_Open() Dim Message, Title, Default, Password As String Dim wbname As String Message = "Enter your password" ' Set prompt. Title = "Password" ' Set title. Default = " " ' Set default. ' Display message, title, and default value. Password = InputBox(Message, Title, Default) If Password = "test" Then wbname = ThisWorkbook.FullName SetAttr wbname, vbReadOnly Else wbname = ThisWorkbook.FullName SetAttr wbname, vbNormal End If End Sub
This code disables saving changes to the workbook, but it will make a copy of the workbook and prompts you to save under another name. I do not know how to disable Excel from automatically making a copy of the workbook though.
Maybe another person will suggest a better way to do it?