[英]Paste text to textbox via button VBA Excel
I want a copy and a paste button in MS Excel, the copy button looks like this 我想要在MS Excel中复制和粘贴按钮,复制按钮看起来像这样
Private Sub CommandButton1_Click()
Dim MyData As New DataObject
MyData.SetText TextBox1.Text
MyData.PutInClipboard
End Sub
Now, how can I make/code a PASTE button in a similar fashion? 现在,如何以类似的方式制作/编码粘贴按钮?
As mentioned in the comments, the post from Get text from clipboard using GetText - avoid error on empty clipboard helped me arrive at the solution that I was looking for. 如评论中所述, 使用GetText从剪贴板获取文本的文章-避免在空剪贴板上出现错误,这有助于我找到所需的解决方案。
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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.