我有一个代码,用于使用一个“主”复选框来选择/取消选择所有复选框。此代码用于 OLEObjects/Active X 控件,我很难重写它以与表单控件复选框配合使用。有什么想法吗?
Private Sub CheckBox1_Click()
Dim i As Integer
For i = 2 To 39
ActiveSheet.OLEObjects("CheckBox" & i).Object.Value = ActiveSheet.CheckBox1.Value
Next i
End Sub
答案1
这似乎有效:
Sub ytrewq()
Dim v As Variant
With ActiveSheet
v = .CheckBoxes(1).Value
n = .CheckBoxes.Count
For i = 2 To n
.CheckBoxes(i) = v
Next i
End With
End Sub
答案2
或者:
Sub Ia_Click()
For i = 41 To 78
ActiveSheet.CheckBoxes(i).Value = ActiveSheet.CheckBoxes(40).Value
Next i
End Sub