Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lock/unlock sheets

Status
Not open for further replies.

Jaffey

Technical User
Jul 18, 2006
72
0
0
CA
Jaffey (TechnicalUser) 12 Jan 07 12:23
I have a spreadsheet with about 20 tabs. I need a macro to unlock/lock all of them. Problem is, sometimes some of them are already locked/unloced so my macro bombs.

Sub Macro1()
'
ActiveSheet.Next.Select
ActiveSheet.Unprotect
ActiveSheet.Next.Select
ActiveSheet.Unprotect

End Sub

Can anyone help with a macro that will unlock or lock all sheets? If it could enter the password as well that would be great.
 
Hi,
Sub Un_Lock()
Dim sh As Worksheet
For Each sh In Application.Worksheets
sh.Unprotect
Next
End Sub

Sub Re_Lock()
Dim sh As Worksheet
For Each sh In Application.Worksheets
sh.Protect
Next
End Sub

Jean-Paul
Montreal
To send me E-Mail, remove “USELESSCODE”.
jp@USELESSCODEsolutionsvba.com
 
1) Click the first tab
2) Hold down the SHIFT key
3) Click the last tab and release SHIFT
4) Press Ctrl-A
5) Right-click and choose Format Cells
6) Click unlock/lock
 
I thought you were talking about something else... Use JP's code.

sh.Unprotect("an_easy_password")
sh.Protect("an_easy_password")
 
You're script works great except now when I lock them it doesn't prompt me to assign a password, it just locks them all without a password which is a problem. Any suggestions? The password is the same for every page if that helps.
 


The Protect method has and argument for password.

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top