简体   繁体   English

VBA:如何引用ComboBox对象

[英]VBA: How To Reference ComboBox Object

I have created a lone ComboBox on the first worksheet in Excel. 我在Excel的第一个工作表上创建了一个单独的ComboBox。 However, I can't find a way to reference its object. 但是,我找不到引用其对象的方法。

I inserted a module, and one of my subs can successfully reference the following value: 我插入了一个模块,我的一个sub可以成功引用以下值:

Sheets("Sheet1").Name 表( “工作表Sheet1”)。名称

However, the following is not available and throws an error: 但是,以下内容不可用并引发错误:

ComboBox1.Value ComboBox1.Value

Error message is: Run-time error '424': Object required 错误消息是:运行时错误'424':需要对象

Can someone explain how to reference this ComboBox in my worksheet? 有人可以解释如何在我的工作表中引用这个ComboBox吗? Thanks 谢谢

That depends on the type of combo box that you created: 这取决于您创建的组合框的类型:

  • Form Control : Sheets("Sheet1").DropDowns(1) 表格控制Sheets("Sheet1").DropDowns(1)
  • ActiveX Control : Sheets("Sheet1").ComboBox1 ActiveX控件Sheets("Sheet1").ComboBox1

Sheets("Sheet1"). can be omitted if the code is placed inside the VBA module Sheet1 . 如果代码放在VBA模块Sheet1则可以省略。

Also see What is the difference between "Form Controls" and "ActiveX Control" in Excel 2010? 另请参阅Excel 2010中“表单控件”和“ActiveX控件”之间的区别是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM