Add, Cut, Paste methods, Page object, MultiPage control example
The following example uses the Add, Cut, and Paste methods to cut and paste a control from a Page of a MultiPage. The control involved in the cut and paste operations is dynamically added to the form.
This example assumes that the user will add, cut, and then paste the new control.
To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:
- Three CommandButton controls named CommandButton1 through CommandButton3.
- A MultiPage named MultiPage1.
Dim MyTextBox As Control
Private Sub CommandButton1_Click()
Set MyTextBox = MultiPage1.Pages(MultiPage1.Value).Controls_
.Add("MSForms.TextBox.1", "MyTextBox", Visible)
CommandButton2.Enabled = True
CommandButton1.Enabled = False
End Sub
Private Sub CommandButton2_Click()
MultiPage1.Pages(MultiPage1.Value).Controls.Cut
CommandButton3.Enabled = True
CommandButton2.Enabled = False
End Sub
Private Sub CommandButton3_Click()
Dim MyPage As Object
Set MyPage = _
MultiPage1.Pages.Item(MultiPage1.Value)
MyPage.Paste
CommandButton3.Enabled = False
End Sub
Private Sub UserForm_Initialize()
CommandButton1.Caption = "Add"
CommandButton2.Caption = "Cut"
CommandButton3.Caption = "Paste"
CommandButton1.Enabled = True
CommandButton2.Enabled = False
CommandButton3.Enabled = False
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.