irresistible007
Board Regular
- Joined
- Nov 24, 2005
- Messages
- 173
Is there is anyway (i m sure, there is) to copy the text of Textbox to Clipboard.. ? please let me know
Option Explicit
Function CopyTextBox_Text(oTextBox As MSForms.TextBox) As Boolean
Dim oData As DataObject
Set oData = New DataObject
oData.Clear
If Len(oTextBox.Text) <> 0 Then
oData.SetText oTextBox.Text
oData.PutInClipboard
CopyTextBox_Text = True
End If
End Function
Sub test()
If CopyTextBox_Text(Me.TextBox1) Then
ActiveSheet.Paste Range("a1")
Else
MsgBox "No text to paste !", vbExclamation
End If
End Sub
Not so. After reading the help file more carefully, I saw that it copies the selected text of the textbox control.
This being the case, you need to select the text:
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
TextBox1.Copy
Yes, you can achieve the same result with this code but will need to ativate the TextBox first
TextBox1.Copy will copy the whole actual Control Object not its Text .
need to ativate the TextBox first
Private Sub CommandButton1_Click()
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
TextBox1.Copy
End Sub