问题
I'm having issues with an onclick event for a checkbox in a vba form. Basically what I am trying to do is ammend the value of all checkboxes on specific tab to be the same value as a master checkbox. In this instance, it is the 'Use Online' captioned checkbox below (online_toggle in the code) which once clicked should toggle the other checkboxes on the tab 'on' or 'off'. I currently have the following code but it keeps producing an error at 'For Each obj In online.OLEObjects'

Private Sub online_toggle_Click()
Dim ctl As Control
For Each ctl In Me.MultiPage1.Pages(6).Controls
If TypeOf ctl Is MSForms.CheckBox Then
If ctl.GroupName = "online_variants" Then
If ctl.Name <> "online_toggle" Then
ctl.Value = online_toggle.Value
End If
End If
End If
Next ctl
End Sub
N.B. online is the name of the tab on which all of the checkboxes are situated. If it helps the checkboxes affected by the master checkbox are all grouped as online_variants
Cheers,
Jason
回答1:
In a Mutipage the page numbering starts from 0 so if you are trying to refer to the Checkboxes in the Online
tab (7th Tab) then use this
Dim ctl As Control
For Each ctl In Me.MultiPage1.Pages(6).Controls
If TypeOf ctl Is MSForms.CheckBox Then
'~~> Your code here
Debug.Print ctl.Name
End If
Next
来源:https://stackoverflow.com/questions/11309825/toggle-checkboxes-in-a-tab-based-upon-master-checkbox-selection