Vba Excel:克隆表单控件是否可行?

时间:2013-10-24 16:02:10

标签: excel excel-vba vba

我必须生成数百个具有相同项目值的表单控件下拉列表。所以我想尽可能克隆它们。我应该能够改变一些属性,如名称,OnA​​ction 任何想法都会受到很大的赞赏。

1 个答案:

答案 0 :(得分: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