Results 1 to 8 of 8

Thread: Copy/paste text box

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Copy/paste text box

    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

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    There is no real need for copy/paste. Use something like :-
    TextBox2.Value = TextBox1.Value
    Regards
    BrianB
    -------------------------------

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284
    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.

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    it copies text1 INTO text2. isn't that what you wanted to do?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284
    What event is going to tell the program that I want the text from text1 to go into text2?

  6. #6
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    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
    Regards
    BrianB
    -------------------------------

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284
    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.

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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:
    1. 'Copy:
    2. Clipboard.Clear
    3. Clipboard.SetText ActiveControl.Text
    4.   'or this to copy just the selected text:
    5. 'Clipboard.SetText ActiveControl.SelText
    6.  
    7. 'Paste:
    8. ActiveControl.Text = Clipboard.GetText
    9.   'or this to paste over the selected text:
    10. 'ActiveControl.Text = Left(ActiveControl.Text, ActiveControl.SelStart-1) + Clipboard.GetText  + Mid(ActiveControl.Text, ActiveControl.SelStart+ActiveControl.SelLength)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width