protect sheet in VB

  • Thread starter Thread starter Mark Howard
  • Start date Start date
M

Mark Howard

Hi,
I want to use the below line lock a sheet
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True

and assign a password.

then the macro will hide the sheet.
ActiveWindow.SelectedSheets.Visible = False

Another Macro will unhide the sheet and then unlock it
with a password prompt.
ActiveWindow.SelectedSheets.Visible = False
ActiveSheet.Unprotect
but this does not work. I cannot assign a password on
protecting.

any ideas?
 
Mark, try this
ActiveSheet.Protect password:="123", DrawingObjects:=True, _
Contents:=True, Scenarios:=True

or with a input box to select a password

pw = InputBox("What password do you want to use ?")
ActiveSheet.Protect password:=pw, DrawingObjects:=True, _
Contents:=True, Scenarios:=True

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2000 & 97
** remove news from my email address to reply by email **
 
If you protect with code, and want a password, then the password is set with
code. There will be no prompt to set one.

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Password:= "mypass"
ActiveSheet.Unprotect Password:= "mypass"

Also, to unhide a sheet use .Visible = True

If someone tries to unprotect the sheet from the menu, they will get a
prompt for the password.

Hope this helps...Mike F
 

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

Back
Top