CB.WorksheetProtection Example 2

This example activates the target worksheet, unprotects the sheet with the current password, passes a new password, and protects the sheet.

Sub WorksheetProtectionExample2()

   ' The following call activates the target worksheet
   ThisWorkbook.Worksheets("Sheet3").Activate

   ' The following call unprotects sheet with current password 
   CB.WorksheetProtection "passwd", False

   ' The following call passes a new password 
   CB.WorksheetProtection "passwd2", False

   ' The following call protects the sheet 
   CB.WorksheetProtection "passwd2", True

End Sub