以下範例示範資料從 文字框 移動到剪貼簿、從剪貼簿到 資料物件,以及從 資料物件 到另一個 文字框的移動過程。 GetFromClipboard 方法會將資料從剪貼簿轉移到 DataObject。 同時也使用 複製 與 取得文字 方法。
若要使用本範例,請將此範例程式碼複製到表單的宣告部分中。 請確定表單包含:
- 兩個分別名為 TextBox1 和 TextBox2 的 TextBox 控制項。
- 一個名為 CommandButton1 的 CommandButton 。
Dim MyData as DataObject
Private Sub CommandButton1_Click()
'Need to select text before copying it to Clipboard
TextBox1.SelStart = 0
TextBox1.SelLength = TextBox1.TextLength
TextBox1.Copy
MyData.GetFromClipboard
TextBox2.Text = MyData.GetText(1)
End Sub
Private Sub UserForm_Initialize()
Set MyData = New DataObject
TextBox1.Text = "Move this data to the " _
& "Clipboard, to a DataObject, then to "
& "TextBox2!"
End Sub
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。