让PowerPoint Combobox正确列出项目的问题

时间:2010-05-14 14:05:42

标签: vba combobox powerpoint

我正在创建一个PowerPoint,我希望用户能够从组合框中的列表中选择一个项目。在此之后不需要发生任何事情,只是在屏幕上提供他们选择的记录。

我的问题是,我似乎能够填充组合框,用户可以选择一个项目,但每次点击组合框时列表会变长(即每次单击列表时都会重复)。或者,我可以清除组合框,然后填充它,但在这种情况下,用户选择似乎也被清除。

VBA示例1:

Private Sub ComboBox1_DropButtonClick()
With ComboBox1
.AddItem " ", 0
.AddItem "speed", 1
.AddItem "provisionality", 2
.AddItem "automation", 3
.AddItem "replication", 4
.AddItem "communicability", 5
.AddItem "multi-modality", 6
.AddItem "non-linearity", 7
.AddItem "capacity", 8
.AddItem "interactivity", 9
End With
End Sub

VBA示例2:

Private Sub ComboBox1_DropButtonClick()
ComboBox1.Clear
With ComboBox1
.AddItem " ", 0
.AddItem "speed", 1
.AddItem "provisionality", 2
.AddItem "automation", 3
.AddItem "replication", 4
.AddItem "communicability", 5
.AddItem "multi-modality", 6
.AddItem "non-linearity", 7
.AddItem "capacity", 8
.AddItem "interactivity", 9
End With
End Sub

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:4)

因为您在DropButtonClick事件中有代码,所以每次单击下拉列表时,这些项目都会添加到组合框中。尝试添加一些代码以检查组合框是否已在填充之前填充:

Private Sub ComboBox1_DropButtonClick()

    If ComboBox1.ListCount = 0 Then
        With ComboBox1
            .AddItem " ", 0
            .AddItem "speed", 1
            .AddItem "provisionality", 2
            .AddItem "automation", 3
            .AddItem "replication", 4
            .AddItem "communicability", 5
            .AddItem "multi-modality", 6
            .AddItem "non-linearity", 7
            .AddItem "capacity", 8
            .AddItem "interactivity", 9
        End With
    End If

End Sub

然后您不必清除组合框并清除所选项目。