Copy TextBox contents to copy buffer

gemcgraw

Board Regular
Joined
Mar 11, 2011
Messages
72
I would think this has such an easy solution but I have been to Mars and back and still have no solution. I am attempting to copy the text from a TextBox1 into the Windows10 copy buffer by using a command button. I've used all sorts of suggested code and shortcuts. Any suggestions that don't required a mile-long block of code?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I would think this has such an easy solution but I have been to Mars and back and still have no solution. I am attempting to copy the text from a TextBox1 into the Windows10 copy buffer by using a command button. I've used all sorts of suggested code and shortcuts. Any suggestions that don't required a mile-long block of code?
If your TextBox is on a UserForm, then you can use an event procedure something like this...
Code:
Private Sub CommandButton1_Click()
  Dim objData As New MSForms.DataObject
  objData.SetText TextBox1.Text
  objData.PutInClipboard
End Sub

If your TextBox is on a worksheet, then you could use this macro..
Code:
Sub PutTextBox1sTextinClipboard()
  Dim objData As Object
  [COLOR="#008000"][B]' Latebound method of referenceing Microsoft Forms 2.0 Object Library[/B][/COLOR]
  Set objData = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
  objData.SetText TextBox1
  objData.PutInClipboard
End Sub
 
Last edited:
Upvote 0
I am working on a Userform. I assigned your code suggestion to a command button. I get nothing in my copy buffer. The TextBox1 is populated with text. I go to NotePad and attempt to past and it has nothing. I'm working with Windows 10 and Office 2016 (Excel) using the VBA editor 7.1.

If your TextBox is on a UserForm, then you can use an event procedure something like this...
Code:
Private Sub CommandButton1_Click()
  Dim objData As New MSForms.DataObject
  objData.SetText TextBox1.Text
  objData.PutInClipboard
End Sub
 
Upvote 0
I am working on a Userform. I assigned your code suggestion to a command button. I get nothing in my copy buffer. The TextBox1 is populated with text. I go to NotePad and attempt to past and it has nothing. I'm working with Windows 10 and Office 2016 (Excel) using the VBA editor 7.1.

If your TextBox is on a UserForm, then you can use an event procedure something like this...
Code:
Private Sub CommandButton1_Click()
  Dim objData As New MSForms.DataObject
  objData.SetText TextBox1.Text
  objData.PutInClipboard
End Sub
I am using XL2010 on Windows 8.1, so I cannot test what you are telling me, but to the best of my knowledge, the DataObject has not changed and so the code should have worked. Perhaps someone else with your setup will test my code and report back to this thread with their findings.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top