lundi 9 décembre 2019

How to enable/disable CommandButtons by using checkboxes in VBA Excel

The aim is if the checkbox next to the commandbutton "Examine 1" is activated manually the commandbutton "Examine 1" are supposed to be deactivated. Which means that if the overall Button "Execute all" is pushed then all other buttons below will be triggered one by one except the "Examine 1" Button. I have already written the Sub for the "Examine 1" Button and also for the checkBox 1. I just dont know how to get the Sub of the checkbox integrated into the "Examine 1" Sub. Currently, if I push the overall BUtton "Execute all" then the Button "Examine 1" is also executed no matter whether the checkbox is marked or not.

This is the macro of the "Examine 1" Button

Sub Examine_Click()
....
...

This one is Sub for the checkbox which refers to the Sub "Examine_Click()"

Private Sub CheckBox1_Click()

Dim b As Button

Set b = ActiveSheet.Buttons("Button 4")

If CheckBox1.Value = True Then
   b.Enabled = True
   b.Font.ColorIndex = 1
Else: b.Enabled = False
    b.Font.ColorIndex = 15

End If
End Sub



Aucun commentaire:

Enregistrer un commentaire