Need to know how to Unprotect all sheets at once with a macro and then later go back and protect all sheets at once.
Need to know how to Unprotect all sheets at once with a macro and then later go back and protect all sheets at once.
[vba]Sub ProtectAllSheets()
Dim s As Worksheet
For Each s In ThisWorkbook.Sheets
s.Select
Cells.Select
Selection.Locked = True
Selection.FormulaHidden = False
s.Protect Password:="test", DrawingObjects:=True, Contents:=True, Scenarios:=True
Next
End Sub
Sub UnProtectAllSheets()
Dim s As Worksheet
For Each s In ThisWorkbook.Sheets
s.Select
s.UnProtect Password:="test"
Next
End Sub [/vba]
OH! There's a KB entry here:
http://www.vbaexpress.com/kb/getarticle.php?kb_id=142
Just search the KB first, Erays.
~Anne Troy
No need to select anything.
[vba]
Sub Unprotect()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Unprotect Password:="MyPassword"
Next
End Sub
Sub Protect()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Protect Password:="MyPassword", DrawingObjects:=True, Contents:=True, Scenarios:=True
Next
End Sub[/vba]
How would i just unlock the sheet and then lock just the sheet back not the cells
My code does not change the cells from being locked or not.
[VBA] Sub Unprotect()I had to make a change
Dim ws As Worksheet
For Each ws In Worksheets
' Changed Worksheet.Unprotect Password:="MyPassword"
ws.Unprotect Password:="MyPassword"
Next
End Sub
Sub Protect()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Protect Password:="MyPassword", DrawingObjects:=True, Contents:=True, Scenarios:=True
Next
End Sub[/VBA]
Last edited by Erays; 03-20-2005 at 11:14 AM. Reason: spelling
Ok, I mistyped that line in my other reply. Fixed now.