我的组合框不显示VBA中添加的值 [英] My ComboBox doesn't display the values I've added in VBA

查看:466
本文介绍了我的组合框不显示VBA中添加的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向用户表单中的组合框添加选项。当我运行代码时,Excel不会给出任何错误,但是当用户窗体显示时,它不会显示我以前添加到组合框的实体。也就是说,当我点击组合框时,它不显示任何选项,只有一个空行,就好像没有添加任何项目。

I'm trying to add options to a combo box in a userform. When I run the code, Excel doesn't give any errors, however when the userform shows up it doesn't display the entities I have added to the combobox previously. That is, when I click on the combobox, it doesn't show any options, only one blank row, as if no items were added to it.

这是我使用的代码:

Private Sub UserForm_Initialize()
    ComboBox1.AddItem "xxx"
    ComboBox1.AddItem "yyy"
    ComboBox1.AddItem "zzz"
End Sub

我使用以下代码调用宏中的用户表单:

I am using the following code to call the user form within a macro:

UserForm.Show


推荐答案

该问题中给出的代码工作得很好。在我的情况下,代码不起作用,因为我手动将这部分代码输入到VBA中:

The code given in the question works perfectly well. In my case the code didn't work because I manually entered this part of the code into VBA:

Private Sub UserForm_Initialize()

如果您让Excel为您创建此模块而不是自己编写,您的代码应该工作完美。 Excel没有初始化作为默认表单,所以我尝试激活,它的工作。

If you make Excel create this module for you instead of writing it on your own, your code should work perfectly. Excel did not have "Initialize" as a default form so I tried "Activate" and it worked.

要创建此模块,您必须执行以下步骤:

To create this module you have to do the following steps:


  1. 右键单击用户表单

  2. 点击查看代码

  3. 顶部你会看到两个可以选择的类别,你应该选择Userform和Activate,在完成此步骤之后,excel必须在你的代码中添加一个新的模块。

  4. 在这个你可以编辑你想要的关于组合框内容的所有内容。

  1. Right click on user form
  2. Click on view code
  3. On top you will see two categories you can pick, you should pick "Userform" and "Activate", after completing this step excel must add a new module to your code.
  4. In this module you may code everything you want about the content of the combobox.

你还应该小心拼写你的组合框,如果你拼错了,你可能无法看到组合框的内容。

You should also be careful with the spelling of your combobox, if you spell it incorrectly, you may be unable to see the contents of the combobox.

这篇关于我的组合框不显示VBA中添加的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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