以下範例使用剪 切 與 貼上 方法,將文字從一個 文字框 中剪切並貼到另一個 文字框中。
若要使用本範例,請將此範例程式碼複製到表單的宣告部分中。 請確定表單包含:
- 兩個分別名為 TextBox1 和 TextBox2 的 TextBox 控制項。
- 一個名為 CommandButton1 的 CommandButton 。
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
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。