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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toggle Between Protected and Unprotected 1

Status
Not open for further replies.

shelby55

Technical User
Jun 27, 2003
1,229
CA
Hello

I am using Excel 2010.

I have a workbook where the number of worksheets that I need to make "read only" will vary with each project.

I want to create a toggle button to freeze and unfreeze these pages with a password...it will always be where I freeze all or unfreeze all, never singlular worksheets.

I recorded the macro on one sheet and got the following code:
Code:
sub test()

Sheets("1").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection=xlNoSelection
End Sub

How do I translate this into VBA code for my toggle button to include all worksheets of my workbook? Thanks.
 
A starting point:
Code:
Sub test()
For Each s In ActiveWorkbook.Worksheets
    s.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    s.EnableSelection = xlNoSelection
Next
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top