2017-08-29 446 views
0

我试图显示文本默认情况下选择在窗体控件combo box中。我已经尝试了以下,但似乎没有工作。有人可以请建议我做错了什么?VBA:将默认值分配给窗体控件组合框

选项1:

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

选项2:

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

,但我得到这个错误

enter image description here

+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 

希望这会有所帮助。

+0

谢谢,但不幸的是没有工作。你可以分享一些可以运行的代码吗? –

0

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

注意DropDown是VBA对象是指Form_Control ComboBox

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 
+0

感谢您的回答。但是这一直不断地在下拉菜单中添加相同的值“选择您的选择”。我怎样才能避免这种情况? –