我正在使用循环控制表单的代码(从这里开始)。 当我找到特定的列表框控件时,我想获取列表框索引。 如何在给定通用控件的情况下访问列表框属性?
答案 0 :(得分:0)
像这样(未经测试):
Dim lb as MSForms.ListBox
Dim ctrl as MSForms.Control
For each ctrl in UserForm.Controls
If TypeName(ctrl) = "ListBox" Then
Set lb = ctrl
'Voila! Now you have a variable "lb" which represents the generic listbox control
MsgBox lb.Name & " listIndex = " & lb.ListIndex 'etc.
End If
Next