Paste、PutInClipboard、SetText 方法示例Paste, PutInClipboard, SetText methods example

下面的示例演示了如何将一个**TextBox** 中的数据移动到**Dataobject, 从dataobject** 到剪贴板, 以及从剪贴板到另一个TextBoxThe following example demonstrates data movement from a TextBox to a DataObject, from a DataObject to the Clipboard, and from the Clipboard to another TextBox.

PutInClipboard 方法将数据从DataObject传输到剪贴板。The PutInClipboard method transfers the data from a DataObject to the Clipboard. 也可以使用**SetText** 和**Paste** 方法。The SetText and Paste methods are also used.

若要使用此示例,请将此示例代码复制到窗体的 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.
Dim MyData As DataObject 
 
Private Sub CommandButton1_Click() 
 Set MyData = New DataObject 
 
 MyData.SetText TextBox1.Text 
 MyData.PutInClipboard 
 
 TextBox2.Paste 
End Sub 
 
Private Sub UserForm_Initialize() 
 TextBox1.Text = "Move this data to a " _ 
 & "DataObject, to the Clipboard, then to " _ 
 & "TextBox2!" 
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.