0

我必须生成数百个具有相同项目值的表单控件下拉列表。所以我想尽可能克隆它们。而且我应该能够更改一些属性,例如名称,OnA​​ction任何想法将不胜感激。

4

1 回答 1

1
Sub Macro1()
Dim c As Range, i As Long, nm As String
Dim sht As Worksheet

    Set sht = ActiveSheet
    i = 0
    For Each c In sht.Range("A2:A20")
        i = i + 1
        nm = "dd_" & i
        On Error Resume Next
        sht.Shapes(nm).Delete
        On Error GoTo 0

        With sht.DropDowns.Add(c.Left, c.Top, c.Width, c.Height)
            .Name = nm
            .ListFillRange = "K1:K6"
            .LinkedCell = ""
            .DropDownLines = 8
            .Display3DShading = False
            .OnAction = "HandleClick"
        End With

    Next c

End Sub

处理程序:

Sub HandleClick()
    Debug.Print Application.Caller
End Sub
于 2013-10-24T17:56:02.160 回答