Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba VAB Excel表单-列表框索引属性给定控件-类型不匹配_Vba_Listbox_Controls - Fatal编程技术网

Vba VAB Excel表单-列表框索引属性给定控件-类型不匹配

Vba VAB Excel表单-列表框索引属性给定控件-类型不匹配,vba,listbox,controls,Vba,Listbox,Controls,我使用的代码(从这里开始)在表单的控件之间循环。 当我找到一个特定的listbox控件时,我想得到listbox索引。 如何访问给定通用控件的listbox属性?类似这样的内容(未测试): 我想“从这里”的意思是从某处开始。你能链接到它,或者在你的问题中粘贴一些代码吗?谢谢David。我几乎做到了。缺少“MSForms.”前缀。我猜这应该是Excel中的假设,但包括它阻止了我的“类型不匹配”错误。如果您不确定变量的类型,您可以始终将lb作为变量或作为对象,尽管这不会像强类型变量那样为您提供智能感

我使用的代码(从这里开始)在表单的控件之间循环。 当我找到一个特定的listbox控件时,我想得到listbox索引。 如何访问给定通用控件的listbox属性?

类似这样的内容(未测试):


我想“从这里”的意思是从某处开始。你能链接到它,或者在你的问题中粘贴一些代码吗?谢谢David。我几乎做到了。缺少“MSForms.”前缀。我猜这应该是Excel中的假设,但包括它阻止了我的“类型不匹配”错误。如果您不确定变量的类型,您可以始终将lb作为变量
作为对象
,尽管这不会像强类型变量那样为您提供智能感知帮助,代码应该以任何一种方式工作。
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