Copy TextBox contents to Clipboard

harveya915

Board Regular
Joined
Sep 4, 2015
Messages
141
In Outlook, I have a UserForm with multiple text boxes and combo boxes and one command button. Once all the fields have been completed and you click on the command button, it transfers all the information from the text boxes and combo boxes to another text box within the same UserForm.

Now I'm trying to have the contents that were transferred to the text box to also be copied to the clipboard to be able to be pasted somewhere else.

This is what i have for the button:

VBA Code:
Private Sub CommandButton1_Click()
TextBox4.Value = ComboBox2.Text & " - " & TextBox1.Text & " - " & TextBox2.Text & " - " & TextBox5.Text & " - " & TextBox3.Text & " - " & ComboBox3.Text & " - " & ComboBox4.Text

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
You can use DataObject to store and transfer data...

VBA Code:
Private Sub CommandButton1_Click()

    TextBox4.Value = ComboBox2.Text & " - " & TextBox1.Text & " - " & TextBox2.Text & " - " & TextBox5.Text & " - " & TextBox3.Text & " - " & ComboBox3.Text & " - " & ComboBox4.Text
   
    Dim dataObj As MSForms.DataObject
    Set dataObj = New MSForms.DataObject
   
    With dataObj
        .SetText TextBox4.Value
        .PutInClipboard
    End With

End Sub

Hope this helps!
 
Upvote 0
Solution
You can use DataObject to store and transfer data...

VBA Code:
Private Sub CommandButton1_Click()

    TextBox4.Value = ComboBox2.Text & " - " & TextBox1.Text & " - " & TextBox2.Text & " - " & TextBox5.Text & " - " & TextBox3.Text & " - " & ComboBox3.Text & " - " & ComboBox4.Text
  
    Dim dataObj As MSForms.DataObject
    Set dataObj = New MSForms.DataObject
  
    With dataObj
        .SetText TextBox4.Value
        .PutInClipboard
    End With

End Sub

Hope this helps!
Finally! This seems to be working just fine. I have been trying other codes but none worked. Thanks for all your help!
 
Upvote 0
I seem to be having an issue with this function/code. When I try to paste somewhere else, all that is pasted is 2 squares. Any help would be appreciated.
 
Upvote 0
It looks like you may have copied a unicode character to the clipboard, but trying to paste it where unicode is not supported, such as the Visual Basic Editor and Immediate Window. Where are you trying to paste it?
 
Last edited:
Upvote 0
It looks like you may have copied a unicode character to the clipboard, but trying to paste it where unicode is not supported, such as the Visual Basic Editor and Immediate Window. Where are you trying to paste it?
I'm trying to paste it on to Microsoft Teams. Sometimes I have this issue and sometimes I don't. But let me try and take a look at the link you provided above and see if that helps.
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,701
Members
448,980
Latest member
CarlosWin

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