Protecting/Unprotecting Worksheets within click event handlers
Posted by Jean on July 03, 2001 2:59 PM
On a protected worksheet, the following click event handler code produces an "Unprotect method of Worksheet class failed" message when the code is executed by pressing the associated command button.
If the code is stepped into directly (bypassing the command button), the worksheet is unprotected as expected. Behavior is similar when attempting to Protect unprotected worksheets from a command button, or if the Protect/Unprotect commands are embedded within the called routine (e.g AssignInductorsToBins).
Public Sub AssignInductorsToBinsButton_Click()
' Worksheets("Inductor Sheet").Activate
ActiveSheet.Unprotect
Run ("AssignInductorsToBins")
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Any observations/suggestions on this unexpected command button behavior would be appreciated!
Thanks,
Jean