• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

I would like to find a code to copy from Clipboard straight to a TextBox

Fred Wayne

Member
Hello,
I am practicing and trying to learn from your forum every day. My situation is the following: I made a simple userform. I have managed to find the way to copy the captions from the CommandButton to the Clipboard and then that caption be pasted somewhere else. What I want is copy the caption of that CommandButton straight to the TextBox. I mean...once I click the CommandButton, that information to be automatically pasted in the TextBox.

Code:
Private Sub CommandButton1_Click()
Dim MyData As New DataObject
  MyData.SetText "Apples: "
 MyData.PutInClipboard
End Sub

Private Sub CommandButton2_Click()
Dim MyData As New DataObject
  MyData.SetText "Tomatoes: "
 MyData.PutInClipboard
End Sub

Private Sub CommandButton3_Click()
Dim MyData As New DataObject
  MyData.SetText "Radish: "
 MyData.PutInClipboard
End Sub

Above I put the code that I am using to copy the CommandButton Captions in the Clipboard, but how can I make what is copied in the clipboard to be automatically pasted in the TextBox when clicking on the CommandButton?

Always so thankful for your teaching and great efforts you do for us to learn.

Thank you so much.
 

Attachments

  • Caption.JPG
    Caption.JPG
    64.4 KB · Views: 5
  • Click on button.JPG
    Click on button.JPG
    15.8 KB · Views: 5
  • Copy to Cliboard and paste to TextBox.xlsm
    12.7 KB · Views: 4
Code:
Private Sub CommandButton1_Click()
  TextBox1.Text = "Apples: "
End Sub

etc
 
I would Say
Code:
Private Sub CommandButton1_Click()
 Me.TextBox1.Value = CommandButton1.Caption
End Sub

Private Sub CommandButton2_Click()
 Me.TextBox1.Value = CommandButton2.Caption
End Sub
Private Sub CommandButton3_Click()
 Me.TextBox1.Value = CommandButton3.Caption
End Sub
 
Back
Top