2017-08-29 444 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

感謝您的回答。但是這一直不斷地在下拉菜單中添加相同的值「選擇您的選擇」。我怎樣才能避免這種情況? –