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

时间:2017-05-12 03:55:22

标签: vba excel-vba combobox activex excel

我有一堆Comboboxes(ActiveX元素),想要遍历所有这些元素以填充它们,如果它旁边有一个x并且如果没有则将它们清空。这已经有效,但是当我在清空后清除组合框的文本/值时,我收到错误。有什么想法吗?

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

1 个答案:

答案 0 :(得分:2)

使用.Object的{​​{1}}属性检索OLEObject对象及其常用方法。

ComboBox

您甚至可以对变量ComBx.Object.value = "" 进行调暗,并为其方法设置Intellisense:

Combobox