Copy textbox text to clipboard

lipanook

New Member
Joined
Nov 29, 2012
Messages
23
It seems like this is the sort of question that would have been asked before, so I apologise if this has been answered previously. However, I can't find any suitable answers on this site or through Google.

I have a userform with a multi-line textbox. This textbox is automatically populated with text generated by various concatenated arrays and strings.

What I would like to do is have a button on the form that copies the text from the textbox onto the clipboard so that the user can just paste it into a third party program.

I would have thought the code would be quite simple. Something like "usrForm.txtBox.Value.Copy" perhaps? Any thoughts?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
If the code is in the userform, then:
Code:
   Me.txtBox.Copy
 
Upvote 0
Hi Lipanook.

Your are vaery near to the exact solution just use the below code.

usrForm.txtBox.text.Copy

Regards
Prince
 
Upvote 0
add a reference to Microsoft Forms 2 Object Library
then from your button add:

Code:
Private Sub CommandButton1_Click()
    With New MSForms.DataObject
        .SetText TextBox1.Text
        .PutInClipboard
    End With
End Sub

Change textbox name as required.

Dave
 
Upvote 0
Thanks for your replies.

Only one worked though, that was dmt32's suggestion.

I tried both Rory's and Prince's suggestions, but Rory's did nothing (no error message and nothing in the clipboard). I had already tried Prince's suggestion but an error message told me that .text was an invalid qualifier. Thanks for your efforts though.

 
Upvote 0
Sorry - I somehow read your question as implying you had selected the text. If not you'd need something like
Code:
   With Me.txtBox
      .SelStart = 0
      .SelLength = Len(.Text)
      .Copy
   End With
FWIW.
 
Upvote 0
Dinossaurs are alive? No, but this precise thread has a similar doubt to mine, so here goes:

I have a sheet where I put in some information and generates 3 textboxes with a predefined text and the said information, so I can copy it and just paste in e-mail to send to partners. I already made a buttom with a macro to delete textboxes so I can generate new:

Code:
Sub DeleteTextBoxes()
    Dim i As Long
    With ActiveSheet.Shapes
        For i = .Count To 1 Step -1
        If .Item(i).Type = msoTextBox Then
        .Item(i).Delete
        End If
    Next i
    End With
    Range("F12").Select
End Sub

I happen to think that the code above has somewhat the resources I need, since I also happen to need 3 macros, one for each textbox to copy. And since the name of the textbox is automatically generated, every time is a different name, how can I make a macro to identify the first, second, and third created texbox in the sheet so I can make a buttom to copy one at a time? Or maybe another solution will do?

Thanks in advance for the help!
 
Upvote 0
Hi all, I have a txtbox on my worksheet. The name of that worksheet is "Deletion Task". I would like to have a 'copy' button that will copy all the texts from that txt box so I can then paste on my notepad etc.
Remember, the txtbox is on a worksheet and NOT on the userform. It the txt box was on userform I could have used the below code:

With Me.txtResult
.SelStart = 0
.SelLength = Len(.Text)
.Copy
End With

How can I edit the code above if the txtbox is on the Worksheet. The same code above doesn't copy the text to clipboard I have tried :(
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,091
Latest member
gaurav_7829

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