从其他空的组合框中清除文本(活动 x)

Clearing text from otherwise empty combobox (active x)

我有一堆组合框(ActiveX 元素),如果旁边有 x,我想遍历所有组合框以填充它们,如果没有,则清空它们。这已经有效,但是当我在清空组合框后尝试清除 text/value 时出现错误。有什么想法吗?

Dim ws2 as worksheet
Dim ComBx As OLEObject
Dim Name As String
Dim NameParaWS3
Dim ComboFill As Range
Dim VisibleFill As Range

For Each ComBx In ws2.OLEObjects
ComBx.ListFillRange = ""
    If ComBx.progID Like "Forms.ComboBox.1" Then
        If ws2.Cells(ComBx.TopLeftCell.row, AlphaCol).Value = "X" Then
        Name = ws2.Cells(ComBx.TopLeftCell.row, 2).Value
        Set NameParaWS3 = ws3.Range("1:1").Find(Name, LookAt:=xlWhole)
        Set ComboFill = ws3.Range(ws3.Cells(2, NameParaWS3.Column), ws3.Cells(LastRow3, NameParaWS3.Column))
        Set VisibleFill = ComboFill.SpecialCells(xlCellTypeVisible)
            Debug.Print ComBx.Name & " located at " & ComBx.TopLeftCell.Address(False, False, xlA1) & ", belongs to parameter '" & Name & "' and is alphanumeric"
            With ComBx
                .ListFillRange = ComboFill.Address(0, 0, xlA1, True)
            End With
        Else:   ComBx.ListFillRange = ""

 'This is the part where I'm getting the error.None of these worked:
                'ComBx.Clear
                'ComBx.Value = ""
                'ComBx.Text= ""
        End If
    End If
Next ComBx

使用 OLEObject.Object 属性 检索 ComboBox 对象及其常用方法。

ComBx.Object.value = ""

您甚至可以调暗变量 a Combobox 并为其方法设置 Intellisense:

Dim cmb as ComboBox: Set cmb = ComBx.Object
cmb.value = ""