VBA-Excel 如何清除组合框项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14209383/
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-Excel How to clear ComboBox Items
提问by SaiKiran Mandhala
i have a ComboBox with 3 items as "Select","Hyman" and "Jill". Under Private Sub Workbook_Open()I kept the following lines of code.
我有一个 ComboBox,其中有 3 个项目,分别是“Select”、“Hyman”和“Jill”。在Private Sub Workbook_Open() 下,我保留了以下代码行。
With ThisWorkbook.Sheets("Sheet1").ComboBox1
Items.Clear
.AddItem "Select"
.AddItem "Hyman"
.AddItem "Jill"
End With
When ever i select an item and close the excel. Next time if i open the excel by default comboBox showing the previously selected item. But i want to show selectas a default item.
当我选择一个项目并关闭 Excel 时。下次如果我默认打开 excel 组合框显示以前选择的项目。但我想将选择显示为默认项目。
回答by Sorceri
You need to remove Items.Clear
should be just .Clear
and then use .SelText
property to set the selected text
您需要删除Items.Clear
应该只是.Clear
然后使用.SelText
属性来设置所选文本
With ThisWorkbook.Sheets("Sheet1").ComboBox1
.Clear
.AddItem "Select"
.AddItem "Hyman"
.AddItem "Jill"
.SelText = "Select"
End With