1

I want a copy and a paste button in MS Excel, the copy button looks like this

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?

4
  • where are both the textboxes? Commented Jun 24, 2015 at 11:14
  • in a userform excel textboxname(txtKordinatat) Commented Jun 24, 2015 at 11:16
  • both are on the same form? Commented Jun 24, 2015 at 11:16
  • No I do not want to copy from textbox1 in TextBox2 //. I just need a paste text into the textbox where I'm writing Commented Jun 24, 2015 at 11:19

1 Answer 1

2

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.

    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"
Sign up to request clarification or add additional context in comments.

1 Comment

++ For figuring it out yourself ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.