我试图隐藏了一堆基于选项按钮,复选框的每个复选框,但我不断收到“错误1004:应用程序定义或对象定义的错误”:对于阵列
Sub FU_EAL_PA_Toggle()
Dim cb As CheckBox
Dim MyCheckboxes As Variant
MyCheckboxes = Array(_
"FU_EAL_PA1", _
"FU_EAL_PA2", _
"FU_EAL_PA3", _
"FU_EAL_PA4", _
"FU_EAL_PA5", _
"FU_EAL_PA6", _
"FU_EAL_PA7", _
"FU_EAL_PA8", _
"FU_EAL_PA8", _
"FU_EAL_PA9", _
"FU_EAL_PA10")
If ActiveSheet.OptionButtons("FU_PA_NotAttendingEAL").Value = 1 Then
For Each cb In ActiveSheet.CheckBoxes(MyCheckboxes)
With ActiveSheet.CheckBoxes(MyCheckboxes)
.Enabled = True
.Visible = True
End With
Next cb
Else
For Each cb In ActiveSheet.CheckBoxes(MyCheckboxes)
With ActiveSheet.CheckBoxes(MyCheckboxes)
.Enabled = False
.Visible = False
End With
Next cb
End If
End Sub
- 有没有更好的方法来做到这一点? (请注意,我将为另一个按钮子集重复此代码,所以我不能循环浏览表单上的所有控件)。
- 我在这里做错了什么?
您可以将控件归为http://www.excelforcommerce.com/grouping-checkboxes-in-excel/(或将它们放在组框控件中),然后像'ActiveSheet.Shapes(“Group 1”) .Visible =(ActiveSheet.OptionButtons(“FU_PA_NotAttendingEAL”)。Value = 1)' – Slai
完美!那就是诀窍,谢谢! –