VBA - 将组合框(userform)中的选定值分配给变量

时间:2010-06-24 00:45:40

标签: vba

我在VBA中的userform中有一个组合框,并希望将用户选择为变量。 IE,我有一个值为1-50的组合框,想要取他们选择的数字并将其用作变量。感谢。

1 个答案:

答案 0 :(得分:1)

你可以;

Dim str as String

''always available, what was selected or typed into the box:
str = TheComboBox.Text
msgbox "drop down text: " & str

''for drop-downs, always returns the text of an item:
if (TheComboBox.ListIndex > -1) then
    ''something is selected;
    str = TheComboBox.List(ComboBox1.ListIndex)
    msgbox  "drop down value: " & str
end if