Code to protect sheets, protects work book also?

T

thiaga

I am trying to protect to 2 worksheets upon work book open

Code:
Private Sub Workbook_Open()
Password = "1234"
Sheets("MasterData").Visible = xlSheetVeryHidden
Sheets("MasterData").Protect Password, True, True, True
Sheets("Unassigned Requests").Protect Password, True, True, True
End Sub

This works fine and it protects the sheets.
But
1. It protects the workbook also. When i open the excel it asks for a
password, which i dont require and i am not able to remove it
2. When I supply the same password in the excel (Tools > Protection >
UnProtect), it does not work.
 
D

Dave Peterson

You can save a file with a password that prevents others from opening the
file--or prevents them from writing over the file.

File|SaveAs|tools|general options
is where you'd specify that password (and remove it if you want)

maybe????
 
T

thiaga

I dont want the password for the workbook to be set at all.
I just want the sheets to be protected.
 
D

Dave Peterson

Save the workbook as a new name without the password.
close excel

Open windows explorer.
delete the old file
rename the new file to the old name.
 
T

thiaga

Thanks Dave, this works!
But it sets the password when i close it and open again
 
D

Dave Peterson

What password is being set when you open and close and reopen?

If you saved a copy with no password (tools|options|general options under the
File|SaveAs dialog, then you shouldn't be asked for a password.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top