Perform a macro by Checkbox Input

951 Views Asked by At

I have Check-Boxes with caption of country Names and a OK button on User-form,

enter image description here

User will Mark required Check-Boxes and click OK to submit the form.

Expected Result: For each checked Box there is a Macro to perform.

How do I make OK button to perform macro on Selected Countries which are Check-Marked by User?

and

Is the following code correctly handle the situation? or there is other way of doing that?

If ActiveDocument.CeemeaFinallist.EasternEurope("CheckBox1").CheckBox.Value = True Then
Application.Run MacroName:="Normal.NewMacros.CEEMEA2"
Else
End If

enter image description here

How do I Select all Check-Boxes at once?

1

There are 1 best solutions below

3
Dave On BEST ANSWER

Try iterating over the controls and firing the macro where the checkbox is set to True:

Private Sub CommandButton1_Click()
Dim ctl As Control
Dim j As Long
For Each ctl In Me.Controls
    If TypeOf ctl Is MSForms.CheckBox Then
        If Me.Controls(ctl.Name).Value = True Then
            ' Fire macro with ctl.Caption to identify the country
        End If
    End If
Next    
End Sub