Password protection worksheet

J

julief

I have a worksheet which I require to have password protected. I have set
the password up in the normal way no problem.
I then want users to be able to run a macro to select a custom view, I have
attached the following code to the macro which will allow the view to be run
without requesting a password (if the bit with password isnt in there is does
ask the user to input the password before showing the custom view).
' Sheets("sheet 2"). Unprotect Password = "mypassword"
ActiveWorkbook.CustomViews("2 - Monday View").Show
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowSorting:=True
Range("L9").Select
Sheets("sheet 2").Protect Password = "mypassword"
End Sub

However, whilst the macro appears to work it doesnt put the password back on
the worksheet. The user can just go to unprotect sheet and click on ok which
is what I need to stop.

any help would be most welcome.
 
B

Bernie Deitrick

Julie,

You need the correct syntax
Sheets("sheet 2").Unprotect Password:="mypassword"


Sheets("sheet 2").Protect Password:="mypassword"

HTH,
Bernie
MS Excel MVP
 

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