简体   繁体   English

TypeOf 对象未检测到 Excel vba 用户表单中的标签和文本框

[英]TypeOf object not detecting label and textbox in excel vba userforms

Problem问题

I have a function whereby it detect an object and behave accordingly.我有一个功能,它可以检测一个对象并做出相应的行为。 But whenever a label object or textbox object, it is not detecting those as label and textbox and thus skipping the if conditions.但是每当标签对象或文本框对象时,它不会将它们检测为标签和文本框,从而跳过if条件。 By the way all objects are from a userform.顺便说一下,所有对象都来自用户表单。 The strange thing is, it is able to detect combobox objects and execute if conditions correctly奇怪的是,它能够检测组合框对象并if条件正确时执行

My Codes我的代码

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

I call the above function as stated below我调用上述函数如下

Call enterObjectsValue(mainPage.customerGroup)

Does anyone knows why?有谁知道为什么?

In this case I would use msforms.TextBox etc.在这种情况下,我会使用 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM