Cut 和 Paste 方法、TextBox 控件示例Cut, Paste methods, TextBox control example

以下示例使用**cut** 和**paste** 方法从一个**TextBox** 中剪切文本, 然后将其粘贴到另一个textbox中。The following example uses the Cut and Paste methods to cut text from one TextBox and paste it into another TextBox.

若要使用此示例,请将此示例代码复制到窗体的 Declarations 部分。To use this example, copy this sample code to the Declarations portion of a form. 确保该窗体包含:Make sure that the form contains:

  • 两个名称分别为"TextBox1"和"TextBox2"的 TextBox 控件。Two TextBox controls named TextBox1 and TextBox2.
  • 一个名为"CommandButton1"的 CommandButtonA 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

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.