CanPaste Property

Applies To

ComboBox control, Frame control, Page object, TextBox control, UserForm object.

Description

Specifies whether the Clipboard contains data that the object supports.

Syntax

object.CanPaste

The CanPaste property syntax has these parts:

Part

Description

object

Required. A valid object.


Return Values

The CanPaste property return values are:

Value

Description

True

The object underneath the mouse pointer can receive information pasted from the Clipboard (default).

False

The object underneath the mouse pointer cannot receive information pasted from the Clipboard.


Remarks

CanPaste is read-only.

If the Clipboard data is in a format that the current target object does not support, the CanPaste property is False. For example, if you try to paste a bitmap into an object that only supports text, CanPaste will be False.

See Also

Paste 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