VBA:如何引用 ComboBox 对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44083621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA: How To Reference ComboBox Object
提问by JRomeo
I have created a lone ComboBox on the first worksheet in Excel. However, I can't find a way to reference its object.
我在 Excel 的第一个工作表上创建了一个单独的 ComboBox。但是,我找不到引用其对象的方法。
I inserted a module, and one of my subs can successfully reference the following value:
我插入了一个模块,我的一个 sub 可以成功引用以下值:
Sheets("Sheet1").Name
工作表(“工作表1”)。名称
However, the following is not available and throws an error:
但是,以下内容不可用并引发错误:
ComboBox1.Value
组合框1.Value
Error message is: Run-time error '424': Object required
错误消息是:运行时错误“424”:需要对象
Can someone explain how to reference this ComboBox in my worksheet? Thanks
有人可以解释如何在我的工作表中引用这个 ComboBox 吗?谢谢
回答by Leviathan
That depends on the type of combo box that you created:
这取决于您创建的组合框类型:
- Form Control:
Sheets("Sheet1").DropDowns(1)
- ActiveX Control:
Sheets("Sheet1").ComboBox1
- 表单控制:
Sheets("Sheet1").DropDowns(1)
- ActiveX 控件:
Sheets("Sheet1").ComboBox1
Sheets("Sheet1").
can be omitted if the code is placed inside the VBA module Sheet1
.
Sheets("Sheet1").
如果代码放在 VBA 模块内,则可以省略Sheet1
。
Also see What is the difference between "Form Controls" and "ActiveX Control" in Excel 2010?