Ausschneiden von Text aus einem Textfeld und Einfügen in einem anderen Textfeld

Im folgenden Beispiel werden die Methoden Cut und Paste zum Ausschneiden von Text aus einem TextBox-Objekt und zum Einfügen in ein anderes TextBox-Objekt verwendet.

To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:

  • Two TextBox controls named TextBox1 and TextBox2.

  • Eine Befehlsschaltfläche ( CommandButton ) mit der Bezeichnung "CommandButton1".

Dim TextBox1 
Dim TextBox2 
Dim CommandButton1 
 
Sub Item_Open() 
 Set TextBox1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("TextBox1") 
 Set TextBox2 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("TextBox2") 
 Set CommandButton1 = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls("CommandButton1") 
 
 TextBox1.Text = "From TextBox1!" 
 TextBox2.Text = "Hello " 
 
 CommandButton1.Caption = "Cut and Paste" 
 CommandButton1.AutoSize = True 
End Sub 
 
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 und Feedback

Haben Sie Fragen oder Feedback zu Office VBA oder zu dieser Dokumentation? Unter Office VBA-Support und Feedback finden Sie Hilfestellung zu den Möglichkeiten, wie Sie Support erhalten und Feedback abgeben können.