Paste Method
Applies To
ComboBox control, Frame control, Page object, TextBox control, UserForm object.
Description
Transfers the contents of the Clipboard to an object.
Syntax
object.Paste
The Paste method syntax has these parts:
Part | Description |
|
object | Required. A valid object. |
Remarks
Data pasted into a ComboBox or TextBox is treated as text.
When the Paste method is used with a form, you can paste any object onto the form.
See Also
CanPaste property, Copy method, Cut method.
Example
The following example uses the CanPaste property and the Paste method to paste a ComboBox from the Clipboard to a Page of a MultiPage. This sample also uses the SetFocus and Copy methods to copy a control from the form to the Clipboard.
The user clicks CommandButton1 to copy the ComboBox to the Clipboard. The user double-clicks (using the DblClick event) CommandButton1 to paste the ComboBox to the MultiPage.
To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:
- A TextBox named TextBox1.
- A ComboBox named ComboBox1.
- A MultiPage named MultiPage1.
- A CommandButton named CommandButton1.
Note This example also includes a subroutine to illustrate pasting text into a control.
Private Sub UserForm_Initialize()
ComboBox1.AddItem "It's a beautiful day!"
CommandButton1.Caption = "Copy ComboBox to Clipboard"
CommandButton1.AutoSize = True
End Sub
Private Sub MultiPage1_DblClick(ByVal Index As Long, ByVal Cancel As _
MSForms.ReturnBoolean)
If MultiPage1.Pages(MultiPage1.Value).CanPaste = True Then
MultiPage1.Pages(MultiPage1.Value).Paste
Else
TextBox1.Text = "Can't Paste"
End If
End Sub
Private Sub CommandButton1_Click()
UserForm1.ComboBox1.SetFocus
UserForm1.Copy
End Sub
'Code for pasting text into a control
'Private Sub ComboBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
' If ComboBox1.CanPaste = True Then
' ComboBox1.Paste
' Else
' TextBox1.Text = "Can't Paste"
' End If
'End Sub
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 the user will add, then cut, 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( _
"Forms.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
Example
The following example uses the Cut and Paste methods to cut text from one TextBox and paste it into another TextBox.
To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains: