VBA帮助里就有例子:
Dim Mycmd As Control Private Sub CommandButton1_Click()
Set Mycmd = Controls.Add("Forms.CommandButton.1", "CommandButton3", Visible) Mycmd.Left = 18 Mycmd.top = 150 Mycmd.Width = 175 Mycmd.Height = 20 Mycmd.Caption = "非常有趣。" & Mycmd.Name End Sub
Private Sub UserForm_AddControl(ByVal Control As MSForms.Control) Label1.Caption = "控件已被添加。" End Sub |