Share via


Paste、PutInClipboard、SetText 方法範例

下列範例示範從 TextBoxDataObject、從 DataObject 到剪貼簿,以及從剪貼簿到另一個 TextBox的資料移動。

PutInClipboard方法會將資料從 DataObject傳輸到剪貼簿。 也會使用 SetTextPaste 方法。

若要使用本範例,請將此範例程式碼複製到表單的宣告部分中。 請確定表單包含:

  • 兩個分別名為 TextBox1 和 TextBox2 的 TextBox 控制項。
  • 一個名為 CommandButton1 的 CommandButton
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

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應