VBA:将默认值指定给表单控件组合框

时间:2017-08-29 07:04:50

标签: excel-vba combobox form-control vba excel

我正在尝试在表单控件combo box中默认显示文本选择。我尝试过以下但似乎没有用。有人可以建议我做错了吗?

选项1:

 Activesheet.shapes("choose_selection").text = "Select your choice"

选项2:

 Activesheet.shapes("choose_selection").controlformat.text = "Select your choice" 

但我收到此错误

enter image description here

2 个答案:

答案 0 :(得分:0)

在组合框中设置默认值

ListIndex属性使用索引号设置当前选定的项目。 ListIndex = 1设置数组中的第一个值。

Sub ChangeSelectedValue()
  With Worksheets("Sheet1").Shapes("Combo Box 1")
  .List = Array("select your choice","Apples", "Androids", "Windows")
  .ListIndex = 1
 End With
End Sub

希望它会有所帮助。

答案 1 :(得分:0)

首先尝试定义DropDown对象,然后再显示其中的文本。

注意DropDown是引用Form_Control ComboBox的VBA对象。

Dim drpdown As DropDown

' set the drop-down object
Set drpdown = ActiveSheet.DropDowns("choose_selection")

' modify the drop-down properties
With drpdown
    .Text = "Select your choice"
End With