excel vba用户窗体中未检测标签和文本框的对象类型
问题 我有一个功能,它可以检测一个对象并相应地进行操作。但是,每当一个label对象或textbox对象出现时,它不会将它们检测为label和textbox,从而跳过excel vba用户窗体中未检测标签和文本框的对象类型,excel,vba,userform,Excel,Vba,Userform,问题 我有一个功能,它可以检测一个对象并相应地进行操作。但是,每当一个label对象或textbox对象出现时,它不会将它们检测为label和textbox,从而跳过if条件。顺便说一下,所有对象都来自一个userform。奇怪的是,它能够检测组合框对象并正确执行条件 我的代码 Public Function enterObjectsValue(ByVal uiObject As Object) If TypeOf uiObject Is Label Then Cells(DeviceS
if
条件。顺便说一下,所有对象都来自一个userform。奇怪的是,它能够检测组合框对象并正确执行条件
我的代码
Public Function enterObjectsValue(ByVal uiObject As Object)
If TypeOf uiObject Is Label Then
Cells(DeviceSheetLastEmptyCell, headerColumn).Value = uiObject.Caption
End If
If TypeOf uiObject Is TextBox Or TypeOf uiObject Is ComboBox Then
Cells(DeviceSheetLastEmptyCell, headerColumn).Value = uiObject.Value
End If
End Function
我调用上述函数,如下所述
Call enterObjectsValue(mainPage.customerGroup)
有人知道为什么吗?在这种情况下,我会使用msforms.TextBox等
Public Function enterObjectsValue(ByVal uiObject As Object)
If TypeOf uiObject Is msforms.Label Then
'Cells(DeviceSheetLastEmptyCell, headerColumn).Value = uiObject.Caption
Debug.Print uiObject.Caption
End If
If TypeOf uiObject Is msforms.TextBox Or TypeOf uiObject Is msforms.ComboBox Then
'Cells(DeviceSheetLastEmptyCell, headerColumn).Value = uiObject.Value
Debug.Print uiObject.Value
End If
End Function
标签具有文本属性,而不是标题,可能与此有关。文本框的故事相同,文本不是值。小心错误吞咽错误。谢谢@Storax。给出msforms.label
、msforms.TextBox
和msforms.ComboBox
后,一切正常。