Copy TextBox contents to Clipboard

harveya915

Board Regular
Joined
Sep 4, 2015
Messages
102
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,501
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!
 
Solution

harveya915

Board Regular
Joined
Sep 4, 2015
Messages
102
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!
 

harveya915

Board Regular
Joined
Sep 4, 2015
Messages
102

ADVERTISEMENT

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.
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,501
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:

Watch MrExcel Video

Forum statistics

Threads
1,129,685
Messages
5,637,808
Members
416,983
Latest member
LessThanAverageUser

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
Top