VBA-Excel如何清除组合框项目 [英] VBA-Excel How to clear ComboBox Items

查看:66
本文介绍了VBA-Excel如何清除组合框项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ComboBox,其中有3个项目,分别是选择",杰克"和吉尔".在 Private Sub Workbook_Open()下,我保留了以下代码行.

i have a ComboBox with 3 items as "Select","Jack" and "Jill". Under Private Sub Workbook_Open() I kept the following lines of code.

With ThisWorkbook.Sheets("Sheet1").ComboBox1
    Items.Clear
    .AddItem "Select"
    .AddItem "Jack"
    .AddItem "Jill"
End With

每当我选择一个项目并关闭excel时.下次如果我默认情况下打开excel,则显示以前选择的项目的comboBox.但是我想显示 select 作为默认项.

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 select as a default item.

推荐答案

您需要删除 Items.Clear 应该只是 .Clear ,然后使用.SelText 属性可设置所选文本

You need to remove Items.Clear should be just .Clear and then use .SelText property to set the selected text

With ThisWorkbook.Sheets("Sheet1").ComboBox1
    .Clear
    .AddItem "Select"
    .AddItem "Jack"
    .AddItem "Jill"
    .SelText = "Select"
End With

这篇关于VBA-Excel如何清除组合框项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆