复制已有的控件再粘贴的话,那些控件都是没有响应事件的。

解决方案 »

  1.   


    下例在运行时间使用 Add 方法将控件添至窗体,并且用 AddControl 事件来确认控件已被添加。若要使用该示例,请将示例代码复制到某窗体的声明变量部分。确保该窗体包含: 名为 CommandButton1 的命令按钮。
    名为 Label1 的标签。 
    Dim Mycmd as Control
    Private Sub CommandButton1_Click()    Set Mycmd = Controls.Add("MsForms.CommandButton.1") ', CommandButton2,Visible)
        Mycmd.Left = 18
        Mycmd.Top = 150
        Mycmd.Width = 175
        Mycmd.Height = 20
        Mycmd.Caption = "非常有趣。" & Mycmd.Name
        
    End SubPrivate Sub UserForm_AddControl(ByVal Control As _ 
        MSForms.Control)
        Label1.Caption = "控件已被添加。"
    End Sub 没想到VBA帮助中的代码也有错误,应该是Forms,没有MsForms。
    看它对各个控件的说明。 
    ProgID 必需。程序设计标识符。是用于标识对象类的、没有空格的文本串。ProgID 的标准语法是 <Vendor>.<Component>.<Version>。ProgID 会被映射为类标识符 (CLSID)。 单个控件的 ProgID 值:复选框 Forms.CheckBox.1 
    组合框 Forms.ComboBox.1 
    命令按钮 Forms.CommandButton.1 
    框架 Forms.Frame.1 
    图像 Forms.Image.1 
    标签 Forms.Label.1 
    列表框 Forms.ListBox.1 
    框架 Forms.MultiPage.1 
    选项按钮 Forms.OptionButton.1 
    滚动条 Forms.ScrollBar.1 
    数值调节钮 Forms.SpinButton.1 
    TabStrip Forms.TabStrip.1 
    文本框 Forms.TextBox.1 
    切换按钮 Forms.ToggleButton.1