Copying the text from a text box to the clipboard

T

TonyJeffs

Why doesn't this work?
..................................
Private Sub CommandButton1_Click()
UserForm1.TextBox1 = "hi"
UserForm1.TextBox1.Copy
UserForm1.TextBox2.Paste
'why doesn't textbox2 contain "hi"?
End Sub
....................................

Thanks

Tony

ps it says in help:
..................................
Copy Method
Copies the contents of an object to the Clipboard.
<snip>
On a TextBox or ComboBox, it copies the currently selected text.
 
T

Tom Ogilvy

Copy copies the selected text - you don't have any text selected:

Private Sub CommandButton1_Click()
With UserForm1
..TextBox1 = "hi"
..TextBox1.SelStart = 0
..TextBox1.SelLength = Len(TextBox1.Text)
..TextBox1.Copy
..TextBox2.Paste
End With
End Sub

works.

But this is easier:


Private Sub CommandButton1_Click()
With UserForm1
..TextBox1 = "hi"
..TextBox2.Text = .Textbox1.Text
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top