简体   繁体   English

如何在excel VBA中的表单中添加项目到组合框?

[英]How to add items to a combobox in a form in excel VBA?

I am new to VBA. 我是VBA的新手。 I want to create a form where a user selects an item of a combobox and the selection runs a macro.I created a user form in VBA but I am unable to add items to the Combobox.When a user opens the form I want the choices in the combobox to be already loaded.how can I accomplish this? 我想创建一个表单,用户选择一个组合框的项目,选择运行一个宏。我在VBA中创建了一个用户表单,但我无法将项目添加到Combobox。当用户打开表单我想要选择在组合框中已经加载了。我可以完成这个吗?

Thank You 谢谢

The method I prefer assigns an array of data to the combobox. 我喜欢的方法是将一组数据分配给组合框。 Click on the body of your userform and change the "Click" event to "Initialize". 单击用户窗体的主体,将“Click”事件更改为“Initialize”。 Now the combobox will fill upon the initializing of the userform. 现在组合框将填充用户表单的初始化。 I hope this helps. 我希望这有帮助。

Sub UserForm_Initialize()
  ComboBox1.List = Array("1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009", "1010")
End Sub

Here is another answer: 这是另一个答案:

With DinnerComboBox
.AddItem "Italian"
.AddItem "Chinese"
.AddItem "Frites and Meat"
End With 

Source: Show the 资料来源: 显示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM