PDA

View Full Version : Solved: Unprotect/Protect Workbook



zoom38
06-06-2006, 11:23 PM
I would like to have code to unprotect and protect the workbook in my main sub. I tried using workbook.unprotect and workbook.protect but when I do this it does not unlock & lock the sheets. Ive done it using activesheet.unprotect and activesheet.protect in each sub but I wanted to do this once in my main sub. Can it be done using workbook.unprotect? The sub I want to do this in is below.


Sub Main()

Dim ThisSheet As Worksheet

Application.ScreenUpdating = False
Set ThisSheet = ActiveSheet
Call EnterNewMember
If NewMember = "" Then
Exit Sub
End If
ActiveWorkbook.Unprotect
Call AddMemberToTotalsWorkSheet
Call AddMemberToPerfEvalWorkSheet
Call AddMemberToQuarterlyWorksheet
Call AddMemberToMonthlyWorkSheets
Call SortMonthlyWorkSheets
Call SortTotalsWorkSheet
Call SortMonthlyWorkSheetsColumnA
Call ShadeRowsOnMonthlyWorksheets
Call ShadeRowsOnQuarterlyWorksheet
Call ShadeRowsOnPerfEvalWorksheet
Call ShadeRowsOnTotalsWorksheet
ActiveWorkbook.Protect
ThisSheet.Activate
Application.ScreenUpdating = True

End Sub


Thanks
Gary

mdmackillop
06-07-2006, 12:00 AM
Sub DoThings()
DoProtect False
'Do things here
DoProtect True
End Sub

Sub DoProtect(x As Boolean)
For Each sh In Worksheets
If x = False Then sh.Unprotect
If x = True Then sh.Protect
Next
End Sub

zoom38
06-07-2006, 06:26 AM
Thanks MD that worked.

Gary