I was able to duplicate your apparent Forms Control .enabled anomaly in Excel 2010. Apparently the .enabled property works as expected in Excel 2003 (tested by me) and in Excel 2007 (anecdotal evidence from another thread).
I was successful in disabling a Forms control using the .enabled property as a software switch (see the attached file and the code that follows). Another alternative is the hide (.visible = False) the CommandButton when it is supposed to be disabled.
In an ordinary code module such as Module1:
Option Explicit
Sub CommandButton1EventHandler()
Dim bCommandButtonEnabled As Boolean
bCommandButtonEnabled = ActiveSheet.Shapes("Button 1").ControlFormat.Enabled
If bCommandButtonEnabled = True Then
MsgBox "CommandButtonEventHandler() activated on " & Now() & "."
End If
End Sub
Sub DisableCommandButton()
'Locked property enables Button attributes to be changes (e.g. change text)
'Enabled property enables / disables Click Events
ActiveSheet.Shapes("Button 1").Locked = True
ActiveSheet.Shapes("Button 1").ControlFormat.Enabled = False
Debug.Print ActiveSheet.Shapes("Button 1").Locked
Debug.Print ActiveSheet.Shapes("Button 1").ControlFormat.Enabled
MsgBox "The 'Enabled' Property set to 'False' for 'Button 1'."
End Sub
Sub EnableCommandButton()
'Locked property enables Button attributes to be changes (e.g. change text)
'Enabled property enables / disables Click Events
ActiveSheet.Shapes("Button 1").Locked = True
ActiveSheet.Shapes("Button 1").ControlFormat.Enabled = True
Debug.Print ActiveSheet.Shapes("Button 1").Locked
Debug.Print ActiveSheet.Shapes("Button 1").ControlFormat.Enabled
MsgBox "The 'Enabled' Property set to 'True' for 'Button 1'."
End Sub
Lewis
Bookmarks