目录

Clear 方法

优质
小牛编辑
115浏览
2023-12-01

全部显示

从指定命令栏组合框控件(下拉式列表框或组合框)中删除所有列表项并清除文本框(编辑框或组合框)。

注意 该方法不能用于内置命令栏控件。

expression.Clear

expression 必需。该表达式返回一个CommandBarComboBox 对象。

示例

本示例可实现的功能为:检查命令栏“Custom”上组合框控件中的项目数。如果列表中的项目数少于 3,那么本示例清除该列表,在其中添加一个新项目,然后将该新项目显示为组合框控件的默认值。

Set myBar = CommandBars("Custom Bar")
Set myControl = myBar.Controls _
 Type:=msoControlComboBox)
With myControl
 .AddItem "First Item", 1
 .AddItem "Second Item", 2
End With
If myControl.ListCount < 3 Then
 myControl.Clear
 myControl.AddItem Text:="New Item", Index:=1
End If