无法在VBA中为Combobox添加值

时间:2017-08-23 13:09:42

标签: excel vba excel-vba combobox

我正在尝试将值添加到由工作表上的宏创建的组合框中。组合框已创建,但我无法在其中填充数据。

我得到了

  

运行时错误438:对象不支持此属性...

我试图将sComboBox声明为Shape / Object /也将其留空也无济于事。 .list属性上的代码错误。 VBA intellisense也没有获得.list属性。我也尝试使用OLEObjects,但是我得到了不同的编译器错误。

另一个问题是:如何在特定单元格中创建组合框,以便它们不会浮动或相互重叠?

Dim sComboBox
If (wsTO.Cells(intLoopCounter, 5).Value <> "") Then
    cBoxName = "cBox" & wsTO.Cells(intLoopCounter, 5).Value
    Set sComboBox = wsTO.Shapes.AddFormControl(xlDropDown, Left:=Cells(intLoopCounter, 12).Left, _
        Top:=Cells(intLoopCounter + 1, 12).Top, Width:=250, Height:=25)

    With sComboBox
        .Name = cBoxName
        .List = Array("Apple", "Orange")
    End With 
End If

1 个答案:

答案 0 :(得分:2)

而不是:

for index, a in enumerate(b):
    np.insert(b[~np.array([np.any(np.logical_or(a[0]==b, a[1]==b)[j]) for j in range(len(b))])], index, a,  axis = 0)

使用:

With sComboBox
    .Name = cBoxName
    .List = Array("Apple", "Orange")
End With 

或:

        With sComboBox
            .Name = cBoxName
            .ControlFormat.List = Array("Apple", "Orange")
        End With
相关问题