-
1 Attachment(s)
Excel macro mystery
I have a couple of very simple excel macros for protecting and unprotecting a sheet. They work fine if yoy run them by means of a hotkey but give an error when a command button calls the code. Here's this code:
Sub Prot()
'Activate with ctrl/j
Sheets(1).Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
MsgBox "Protected", vbOKOnly
End Sub
Sub Unprot()
'Activate with ctrl/k
Sheets(1).Unprotect
MsgBox "Unprotected", vbOKOnly
End Sub
Sub CommandButton1_Click()
Static i As Integer
If i = 0 Then
Prot
Else
Unprot
End If
I attach the spreadsheet if you want to try it out...
It just doesn't make any sense. Maybe I have overlooked something!?