在现有宏中插入VBA代码以更改listrows属性

时间:2017-07-21 14:11:21

标签: excel-vba vba excel

我正在使用以下宏将多个组合框插入电子表格

Sub Macro4()

    Dim i As Integer, j As Integer
    With ActiveSheet.OLEObjects
             .Delete   ' delete all objects


        For i = 0 To 0
            For j = 0 To 10
               .Add ClassType:="Forms.ComboBox.1", _
                    Left:=i * 280 + 261, _
                    Top:=(j * 15) + 0, _
                    Width:=275, _
                    Height:=15, _
                    Link:=False, _
                    DisplayAsIcon:=False

                .Item(i * 10 + j + 1).LinkedCell = "G" & i * 10 + j + 1
                .Item(i * 10 + j + 1).ListFillRange = "test1"


            Next j
        Next i
    End With
End Sub
很遗憾,我不是作者,我有0个VBA能力,因此我不知道如何让它发生,默认的listrows参数将是60.是否可能?

1 个答案:

答案 0 :(得分:0)

如果您要创建60个组合框,以下内容将起作用:

Sub Macro4()

Dim i As Integer, j As Integer
With ActiveSheet.OLEObjects
         .Delete   ' delete all objects


    For i = 0 To 0
        For j = 0 To 60
           .Add ClassType:="Forms.ComboBox.1", _
                Left:=i * 280 + 261, _
                Top:=(j * 15) + 0, _
                Width:=275, _
                Height:=15, _
                Link:=False, _
                DisplayAsIcon:=False

            .Item(i * 10 + j + 1).LinkedCell = "G" & i * 10 + j + 1
            .Item(i * 10 + j + 1).ListFillRange = "test1"


        Next j
    Next i
End With

End Sub

如果您要查找60个盒子,每列10个,以下内容将起作用:

Sub Macro4()

Dim i As Integer, j As Integer
With ActiveSheet.OLEObjects
         .Delete   ' delete all objects


    For i = 0 To 6
        For j = 0 To 10
           .Add ClassType:="Forms.ComboBox.1", _
                Left:=i * 280 + 261, _
                Top:=(j * 15) + 0, _
                Width:=275, _
                Height:=15, _
                Link:=False, _
                DisplayAsIcon:=False

            .Item(i * 10 + j + 1).LinkedCell = "G" & i * 10 + j + 1
            .Item(i * 10 + j + 1).ListFillRange = "test1"


        Next j
    Next i
End With

End Sub