代码:
Private Sub Form_Load()
Dim cmb As MSForms.CommandButton
Set cmb = Controls.Add("Forms.CommandButton.1", "cmb") '动态添加
cmb.Left = 10
cmb.Top = 10
cmb.Visible = True
End Sub
然后在菜单project ->Project Properties -->Make -->去掉选项Remove information about unused Active controls
Private Sub CommandButton1_Click()
Dim AddCom As Control
If AddCom Is Nothing Then
Set AddCom = Me.Controls.Add("Forms.CommandButton.1", "CommandButtonA", Me)
AddCom.Caption = "ASDADF"
AddCom.Move 100, 100, 300, 300
AddCom.Visible = True
End If
End Sub