如何在VBA中获取ComboBox控件的选中值?
VBA获取UserForm中ComboBox选中值并添加表格行的问题与解决
问题描述
我尝试了多种语法,始终无法获取ComboBox控件的选中值,后续需要用两个ComboBox的值向表格添加新行。
原测试代码
Sub add_termin() Dim lastrow As Long Dim typ As String Dim frist As Date Dim tops As String ThisWorkbook.Activate Set diesesworkbook = ActiveWorkbook lastrow = diesesworkbook.Sheets("Termine").Range("A" & Rows.Count).End(xlUp).Row typ = ComboBox1.Column(1).Value MsgBox (lastrow) 'Hinzufügen neuer Zeile 'diesesworkbook.Sheets("Termine").Range("A" & (lastrow + 1)).Value = ComboBox1.Value 'diesesworkbook.Sheets("Termine").Range("B" & (lastrow + 1)).Value = TestBox1.Value 'diesesworkbook.Sheets("Termine").Range("C" & (lastrow + 1)).Value = ComboBox2.Value End Sub
解决方案
关键在于必须明确指定ComboBox所属的UserForm名称,修正后的取值代码如下:
typ = Termineingabe.ComboBox1.Value
内容的提问来源于stack exchange,提问作者BlankerHans
相关产品推荐
相关产品推荐

