找不到 ActiveX ComboBox 方法或数据成员
ActiveX ComboBox method or data member not found
我在名为 Home
的 sheet 中有一个组合框(名为 userBox
)。它选择了其中一个选项,比方说 "User A"
。我想做的就是将 "User A"
分配给字符串 usr
,但我一直收到编译错误:
Method or data member not found
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 组合框,为什么不同?
Sub blah()
Dim rly As String
rly = Sheets(1).ComboBox1.Value
ThisWorkbook.Sheets(1).Cells(1, 10) = rly
End Sub
单元格 J1 returns 在组合框中选择的值。
如果是ActiveX控件,需要使用OLEObjects
集合来访问它:
Debug.Print ws.OLEObjects("userBox").Object.Text
我在名为 Home
的 sheet 中有一个组合框(名为 userBox
)。它选择了其中一个选项,比方说 "User A"
。我想做的就是将 "User A"
分配给字符串 usr
,但我一直收到编译错误:
Method or data member not found
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 组合框,为什么不同?
Sub blah()
Dim rly As String
rly = Sheets(1).ComboBox1.Value
ThisWorkbook.Sheets(1).Cells(1, 10) = rly
End Sub
单元格 J1 returns 在组合框中选择的值。
如果是ActiveX控件,需要使用OLEObjects
集合来访问它:
Debug.Print ws.OLEObjects("userBox").Object.Text