Excel VBA 用户窗体组合框问题

发布于 2024-08-29 01:14:34 字数 2037 浏览 8 评论 0原文

我在 Excel 文档的用户窗体中使用组合框时遇到困难。 组合框要么不出现在用户窗体中,要么组合框保持空白,当我在其中输入任何字符时,项目列表会出现 2 或 3 次,而不是一次。 当我选择一个项目时,所选项目不会出现在框中。看起来好像 Excel^ 随机选择一项,无论我从列表中选择哪一项,最终显示在框中的项总是相同的。

有人能帮我解决这个问题吗?多谢!!!

这是我使用的代码:

Private Sub ComboBox1_Change()
    Select Case ComboBox1.Text
        Case "Een nieuwe start"
        Case "Alles heeft zijn tijd"
        Case "De wereld aan je voeten"
        Case "Een levend boek"
        Case "Drempels"
        Case "Kerstmis"
        Case "Confituur of choco"
        Case "Hoe groot is de hemel?"
        Case "Ongelovige Thomas"
        Case "Feesten"
        Case "Er is er één jarig!"
        Case "Eén van hart"
        Case "Ervoor gaan"
        Case "Groen gras"
        Case "RELatie"
        Case "Vele plaatjes"
        Case "Iedereen fan"
        Case "Schattenjacht"
        Case "Lichtbakens"
        Case "Rijke Luis"
        Case "Hemel op aarde"
        Case "Op bezoek"

        Case Else
    End Select
End Sub

Private Sub UserForm1_Initialize()
        ComboBox1.Clear
        ComboBox1.AddItem "Een nieuwe start"
        ComboBox1.AddItem "Alles heeft zijn tijd"
        ComboBox1.AddItem "De wereld aan je voeten"
        ComboBox1.AddItem "Een levend boek"
        ComboBox1.AddItem "Drempels"
        ComboBox1.AddItem "Kerstmis"
        ComboBox1.AddItem "Confituur of choco"
        ComboBox1.AddItem "Hoe groot is de hemel?"
        ComboBox1.AddItem "Ongelovige Thomas"
        ComboBox1.AddItem "Feesten"
        ComboBox1.AddItem "Er is er één jarig!"
        ComboBox1.AddItem "Eén van hart"
        ComboBox1.AddItem "Ervoor gaan"
        ComboBox1.AddItem "Groen gras"
        ComboBox1.AddItem "RELatie"
        ComboBox1.AddItem "Vele plaatjes"
        ComboBox1.AddItem "Iedereen fan"
        ComboBox1.AddItem "Schattenjacht"
        ComboBox1.AddItem "Lichtbakens"
        ComboBox1.AddItem "Rijke Luis"
        ComboBox1.AddItem "Hemel op aarde"
        ComboBox1.AddItem "Op bezoek"
        ComboBox1.Text = ComboBox1.List(0)
End Sub

I'm having difficulties with a Combobox in a userform in an Excel document.
The combobox either doesn't appear in the userform, or the combobox remains blank, and when I enter any character in it, the list of items appears, but 2 or 3 times, instead of just once.
When I select an item, the chosen item doesn't appear in the box. It seems as if Excel^picks one at random, and whichever item I choose from the list, it's always the same one that ends up being displayed in the box.

Can anyone help me on this one? Thanks a lot!!!

This is the code I used:

Private Sub ComboBox1_Change()
    Select Case ComboBox1.Text
        Case "Een nieuwe start"
        Case "Alles heeft zijn tijd"
        Case "De wereld aan je voeten"
        Case "Een levend boek"
        Case "Drempels"
        Case "Kerstmis"
        Case "Confituur of choco"
        Case "Hoe groot is de hemel?"
        Case "Ongelovige Thomas"
        Case "Feesten"
        Case "Er is er één jarig!"
        Case "Eén van hart"
        Case "Ervoor gaan"
        Case "Groen gras"
        Case "RELatie"
        Case "Vele plaatjes"
        Case "Iedereen fan"
        Case "Schattenjacht"
        Case "Lichtbakens"
        Case "Rijke Luis"
        Case "Hemel op aarde"
        Case "Op bezoek"

        Case Else
    End Select
End Sub

Private Sub UserForm1_Initialize()
        ComboBox1.Clear
        ComboBox1.AddItem "Een nieuwe start"
        ComboBox1.AddItem "Alles heeft zijn tijd"
        ComboBox1.AddItem "De wereld aan je voeten"
        ComboBox1.AddItem "Een levend boek"
        ComboBox1.AddItem "Drempels"
        ComboBox1.AddItem "Kerstmis"
        ComboBox1.AddItem "Confituur of choco"
        ComboBox1.AddItem "Hoe groot is de hemel?"
        ComboBox1.AddItem "Ongelovige Thomas"
        ComboBox1.AddItem "Feesten"
        ComboBox1.AddItem "Er is er één jarig!"
        ComboBox1.AddItem "Eén van hart"
        ComboBox1.AddItem "Ervoor gaan"
        ComboBox1.AddItem "Groen gras"
        ComboBox1.AddItem "RELatie"
        ComboBox1.AddItem "Vele plaatjes"
        ComboBox1.AddItem "Iedereen fan"
        ComboBox1.AddItem "Schattenjacht"
        ComboBox1.AddItem "Lichtbakens"
        ComboBox1.AddItem "Rijke Luis"
        ComboBox1.AddItem "Hemel op aarde"
        ComboBox1.AddItem "Op bezoek"
        ComboBox1.Text = ComboBox1.List(0)
End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

垂暮老矣 2024-09-05 01:14:34

您有 UserForm1_Initialize ,它永远不会被调用,它必须是 UserForm_Initialize (没有“1”)

You have UserForm1_Initialize which will never get called, it must be UserForm_Initialize (no "1")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文