组合框onclick条件 [英] Combobox onclick condition

查看:70
本文介绍了组合框onclick条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Visual Basic的新手,希望当用户从组合框进行选择时,无需单击确定"或其他任何按钮,就可以使条件正常工作.
我正在处理Excel工作表,因此要搜索的内容更加奇怪.
我不知道要在Google上搜索什么,对不起,这是一个简单的问题.希望我能得到一个简单的答案.

I am new to visual basic, and would like to have a condition working when the user chooses from the combo box, without having to click a button ok or what ever.
I am working on excel sheet and so it''s even more strange on what to search for.
I dont know what to search for on google, i am sorry if it''s a simple question. I hope i''ll get a simple answer.

推荐答案

如果您右键单击工作表的工作表标签,请选择查看代码",然后将此代码粘贴到工作表模块,您应该了解其所有工作原理:-

If you right click on the sheet tab of your worksheet, select View Code and then paste this code into the sheet module you should get some idea of how it''s all working:-

Private Sub ComboBox1_Change()
Select Case ComboBox1.Text
Case "Dogs"
MsgBox "Dogs"
Case "Cats"
MsgBox "Cat"
Case "Mice"
MsgBox "Mice"
Case Else
End Select
End Sub

Private Sub Worksheet_Activate()
ComboBox1.Clear
ComboBox1.AddItem "Dogs"
ComboBox1.AddItem "Cats"
ComboBox1.AddItem "Mice"
ComboBox1.Text = ComboBox1.List(0)
End Sub


每当激活工作表时,就会填充组合框(尽管您也可以在工作簿打开时进行填充).每当在组合框内更改条目时,都会触发Change事件,然后您可以根据用户选择的内容运行不同的代码.

希望这会有所帮助,
圣诞老人


The combobox is populated whenever the sheet is activated (although you could also populate just when the workbook opens). Whenever the entry is changed within the combobox the Change event if fired and you can then run different code depending on what the user has chosen.

Hope this helps,
Santa


这篇关于组合框onclick条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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