我想在MS Excel中使用复制和粘贴按钮,复制按钮看起来像这样
Private Sub CommandButton1_Click()
Dim MyData As New DataObject
MyData.SetText TextBox1.Text
MyData.PutInClipboard
End Sub
现在,我如何以类似的方式制作/编码PASTE按钮?
答案 0 :(得分:2)
正如评论中所提到的,Get text from clipboard using GetText - avoid error on empty clipboard的帖子帮助我找到了我正在寻找的解决方案。
Dim DataObj As MsForms.DataObject
Set DataObj = New MsForms.DataObject
On Error GoTo Whoa
'~~> Get data from the clipboard.
DataObj.GetFromClipboard
'~~> Get clipboard contents
Me.txtKordinatat.Value = DataObj.GetText(1)
Exit Sub
Whoa:
If Err <> 0 Then MsgBox "Data on clipboard is not text or is empty"