未找到ActiveX ComboBox方法或数据成员

时间:2015-08-25 21:50:43

标签: excel vba methods combobox member

我在名为userBox的工作表中有一个组合框(称为Home)。它选择了一个选项,比方说"User A"。我要做的就是将"User A"分配给字符串usr,但我不断收到编译错误:

  

找不到方法或数据成员

Sub fixPls()
Dim row As Integer, col As Integer, usr As String, tbl As String, found  As Boolean, k As Integer, payType As String
Set wb = ThisWorkbook
Set ws = wb.Sheets("Home")
ws.Activate

Application.DisplayAlerts = False
Application.ScreenUpdating = False

lastRow = Range("B16").End(xlUp).row
usr = ws.userBox.Value
tbl = ws.tblBox.Value
payType = ws.tpBox.Value
....
编辑:我在一个新工作簿中尝试了一个虚拟程序,并且它有效。使用activeX comboBox,为什么它不同?

Sub blah()
Dim rly As String
rly = Sheets(1).ComboBox1.Value
ThisWorkbook.Sheets(1).Cells(1, 10) = rly 
End Sub

Cell J1返回在comboBox中选择的值。

1 个答案:

答案 0 :(得分:1)

如果它是ActiveX控件,则需要使用OLEObjects集合来访问它:

Debug.Print ws.OLEObjects("userBox").Object.Text