gpt4 book ai didi

vba - 使 PowerPoint 组合框正确列出项目的问题

转载 作者:行者123 更新时间:2023-12-04 20:13:50 25 4
gpt4 key购买 nike

我正在创建一个 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

任何人都可以帮忙吗?

最佳答案

因为您在 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

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

关于vba - 使 PowerPoint 组合框正确列出项目的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2834713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com