Add a Control to a Page
The following example uses the Add method of the Microsoft Forms 2.0 Controls collection to add a control to a form at run time.
To use this example, copy this sample code to the Script Editor of a form. Make sure that the form contains:
- A CommandButton named CommandButton1.
Dim Mycmd
Sub CommandButton1_Click()
Set Mycmd = Item.GetInspector.ModifiedFormPages("P.2").Controls.Add("Forms.CommandButton.1") ', CommandButton2, Visible)
Mycmd.Left = 18
Mycmd.Top = 150
Mycmd.Width = 175
Mycmd.Height = 20
Mycmd.Caption = "This is fun." & Mycmd.Name
End Sub
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.