PDA

View Full Version : Solved: Text box value to the clipboard



BoatwrenchV8
08-23-2012, 04:07 PM
Hello All,
I have a userform that calculates a number value (integer) and displays it in one of the text boxes on the form. In addtion to the number being displayed, I need it on the clipboard so the user can just paste the number where it is supposed to go in the document. What is the command to copy the value from a text box to the clipboard? The text box name the result is displayed in, is named tb_CalculatedDate, I tried tb_CalculatedDate.Value.PutInClipboard but it did not work. The value was not in the clipboard. Suggestions??
Thanks,
Rich

gmaxey
08-23-2012, 04:29 PM
Something like:

Private Sub CommandButton1_Click()
CopyTextBoxToClipBoard Me.TextBox1.Text
End Sub
Sub CopyTextBoxToClipBoard(ByRef strIn As String)
Dim myCopy As DataObject
'Must have a reference to Microsoft Forms 2.0 Object Library enabled
Set myCopy = New DataObject
myCopy.SetText strIn
myCopy.PutInClipboard
End Sub

macropod
08-23-2012, 04:46 PM
See: http://word.mvps.org/faqs/MacrosVBA/ManipulateClipboard.htm
Dim MyData As DataObject
Set MyData = New DataObject
MyData.SetText tb_CalculatedDate.Value
MyData.PutInClipboard

BoatwrenchV8
08-26-2012, 07:10 PM
Perfect! Thank you both very much!