我想将一组(工作表)控件传递给另一个子以修改其属性:
E.g。
Dim collChk(0 To 2) As ? ' Tried Variant, OLEObject, Control...
collChk(0) = chk0
collChk(1) = chk1
collChk(2) = chk2
子:
Sub SetFalse(ByRef controls As ?)
Dim i As Long
For i = LBound(controls) To UBound(controls)
controls(i) = False
Next i
End Sub
但我一直得到:ByRef Argument Type不匹配或其他错误
它也可能是一个集合,无所谓,但我也无法设置它。我有点迷失方向。最初的想法是将它作为ParamArray传递,但错误也突然出现。
(唯一的好处就是有一个兼容Sheet和UserForm控件的函数,但我希望它们手动指定而不重复。)
答案 0 :(得分:0)
对于CheckBoxes:
Dim collChk(0 To 2) As MSForms.CheckBox
Set collChk(0) = Chk0
Set collChk(1) = Chk1
Set collChk(2) = Chk2
请注意,您需要使用Set
作为对象。然后:
Sub SetFalse(ByRef controls() As MSForms.CheckBox)
Dim i As Long
For i = LBound(controls) To UBound(controls)
controls(i) = False
Next i
End Sub