Bhushan K
Bhushan K

Reputation: 47

Activate form button subject to some condition

I am using a form with two combo-boxes and a button. I want button to be disabled initially and it should enable only when the user selects a valid value in both the combo-boxes.

I tried to disable the button using the form initialize sub-routine but the button appears to be active. What can be the issue? Also how to enable the button using if conditions?

Private Sub UserForm1_Initialize()

    Me.Shapes("ButtonName1").ControlFormat.Enabled = False
    ActiveSheet.Shapes("ButtonName1").Font.ColorIndex = 16

End Sub

Upvotes: 0

Views: 187

Answers (1)

CallumDA
CallumDA

Reputation: 12113

You made a couple of mistakes in your code.

  • UserForm1_Initialize should be UserForm_Initialize
  • You can use Userform.ButtonName1 to access the properties of your button
  • Use TextFrame.Characters.Font.ColorIndex to access the text on a button on the worksheet


The code below should work

Private Sub UserForm_Initialize()
    UserForm1.ButtonName1.Enabled = False
    ActiveSheet.Shapes("ButtonName1").TextFrame.Characters.Font.ColorIndex = 16
End Sub

Upvotes: 1

Related Questions