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
 
If you want to, give this a try.
From SpreadSheetGuru initially from ExcelHero
How To Use VBA Code To Copy Text To The Clipboard — TheSpreadsheetGuru

VBA Code:
Function Clipboard(Optional StoreText As String) As String
'PURPOSE: Read/Write to Clipboard
'Source: ExcelHero.com (Daniel Ferry) via Spreadsheet Guru (Chris Newman)

Dim x As Variant

'Store as variant for 64-bit VBA support
  x = StoreText

'Create HTMLFile Object
  With CreateObject("htmlfile")
    With .parentWindow.clipboardData
      Select Case True
        Case Len(StoreText)
          'Write to the clipboard
            .setData "text", x
        Case Else
          'Read from the clipboard (no variable passed through)
            Clipboard = .GetData("text")
      End Select
    End With
  End With

End Function

You can call it like this but obviously Ctrl+V works for copying from the clipboard
VBA Code:
Sub ExampeMacro()

'Copy text to the clipboard
  Clipboard "I can copy to the Clipboard!"

'To read text from the clipboard:
  MsgBox Clipboard
 
End Sub
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

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