Cut Method

Applies To

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

Description

Removes selected information from an object and transfers it to the Clipboard.

Syntax

object.Cut

The Cut method syntax has these parts:

Part

Description

object

Required. A valid object.


Remarks

For a ComboBox or TextBox, the Cut method removes currently selected text in the control to the Clipboard. This method does not require that the control have the focus.

On a Page, Frame, or form, Cut removes currently selected controls to the Clipboard. This method only removes controls created at run time.

See Also

Copy method, Paste method.

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:

  • Two TextBox controls named TextBox1 and TextBox2.
  • A CommandButton named CommandButton1.
    Private Sub UserForm_Initialize()
        TextBox1.Text = "From TextBox1!"
        TextBox2.Text = "Hello "
        
        CommandButton1.Caption = "Cut and Paste"
        CommandButton1.AutoSize = True
    End Sub
    
    Private Sub CommandButton1_Click()
        TextBox2.SelStart = 0
        TextBox2.SelLength = TextBox2.TextLength
        TextBox2.Cut
    
        TextBox1.SetFocus
        TextBox1.SelStart = 0
        
        TextBox1.Paste
        TextBox2.SelStart = 0
    End Sub