How to lock several sheets including af password?

J

Jane

Sooner I have asked for an easy way to lock all the sheets in a spredsheet
and I got the very useful answer:

Sub LockDown()
For Each ws In Worksheets
ws.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Next
End Sub

Sub UnlockAll()
For Each ws In Worksheets
ws.Unprotect
Next
End Sub

But I like to protect my spredsheet with a password, so the user can't
remove the protection. To that question I got the following answer:

"Open your workbook
Open the VBE (alt-f11)
select your poject
Tools|VBAProject Properties|Protection tab
Give it a memorable password.

Save your workbook, close it and reopen it to test that protection"

But I can't make that work - why?

Jane
 
D

Dave Peterson

That second set of instructions is to protect the workbook's project so that the
users can't see the code (and any included password).

If you want to protect each sheet with the same password, you could use:

Sub LockDown()
For Each ws In Worksheets
ws.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, _
password:="topsecret"
Next ws
End Sub

Sub UnlockAll()
For Each ws In Worksheets
ws.Unprotect password:="topsecret"
Next ws
End Sub

But if the user knows how to get the the VBE, they can read your code and see
the password. That's where the project protection comes in.

ps. Change "topsecret" to your password in both spots.
 
R

Roger Govier

Hi
Jane

Try
Sub LockDown()
For Each ws In Worksheets
ws.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
Password:="Roger"
Next
End Sub

Sub UnlockAll()
For Each ws In Worksheets
ws.Unprotect Password:="Roger"
Next
End Sub


Make the password something far more sensible and memorable than "Roger"
 
D

Dave Peterson

Tyop <bg> alert.

ws.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, _
Password:="Roger"

(Added a comma after the last True in the first line.)
 
J

Jane

Thanks!!
--
Jane


"Dave Peterson" skrev:
Tyop <bg> alert.

ws.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, _
Password:="Roger"

(Added a comma after the last True in the first line.)
 
R

Roger Govier

Glad you are alert Dave, (as always!!)

In the middle of setting up my new Dell laptop with Vista. Typing on the
wrong keyboard half of the time! Well, that's my excuse, anyway.
 

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