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

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

问题描述

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.

Here is the code I'm using:

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

解决方案

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()

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. 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.

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

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