I have an Excel app that uses VB forms. I was wondering if it is possible to be able to copy the contents of one text box and paste into another. I'm not sure how to go about this. Any help would be appreciated.
Thanks
Printable View
I have an Excel app that uses VB forms. I was wondering if it is possible to be able to copy the contents of one text box and paste into another. I'm not sure how to go about this. Any help would be appreciated.
Thanks
There is no real need for copy/paste. Use something like :-
TextBox2.Value = TextBox1.Value
I was looking for being able to highlight text, then right click and select copy, then click in a text box and right-click and select paste.
I don't see how that code is going to accomplish that.
it copies text1 INTO text2. isn't that what you wanted to do?
What event is going to tell the program that I want the text from text1 to go into text2?
Any - it is up to you where you put the code - or put a button on the form. Or in some other code your run. etc etc
ok. Say I put two buttons on the form. One copy and one paste. When the button is clicked, what code returns the object name of the text box that has the selected text to copy in it? The form has approx. 30 to 40 text boxes on it.
ah, well that's a bit different than you had explained before (BrianB's answer works perfectly to copy from one known textbox to another).
I'm not sure if this is the right syntax for VBA, but it wont be far off:
VB Code:
'Copy: Clipboard.Clear Clipboard.SetText ActiveControl.Text 'or this to copy just the selected text: 'Clipboard.SetText ActiveControl.SelText 'Paste: ActiveControl.Text = Clipboard.GetText 'or this to paste over the selected text: 'ActiveControl.Text = Left(ActiveControl.Text, ActiveControl.SelStart-1) + Clipboard.GetText + Mid(ActiveControl.Text, ActiveControl.SelStart+ActiveControl.SelLength)