Results 1 to 8 of 8

VBA Code for a command button to copy a text boxes value?

This is a discussion on VBA Code for a command button to copy a text boxes value? within the Excel Questions forums, part of the Question Forums category; Could someone post the code? Thanks. Also, could you post for the button to just select the value in the ...

  1. #1
    Board Regular
    Join Date
    Aug 2002
    Posts
    187

    Default VBA Code for a command button to copy a text boxes value?

    Could someone post the code? Thanks.

    Also, could you post for the button to just select the value in the text box? Thanks in advance!

  2. #2
    Board Regular
    Join Date
    Feb 2002
    Posts
    384

    Default Re: VBA Code for a command button to copy a text boxes value

    Hey rogersj, The click command for CommandButton1 will copy the value of TextBox1 to my variable myValue. Regards, Marc

    Code:
    Private Sub CommandButton1_Click()
    myValue = TextBox1.Value
    MsgBox myValue
    End Sub

  3. #3
    Board Regular
    Join Date
    Aug 2002
    Posts
    187

    Default Re: VBA Code for a command button to copy a text boxes value

    Wouldn't

    Private Sub CommandButton1_Click()
    myValue = TextBox1.Value
    MsgBox myValue
    End Sub

    display a message box with the text box value? I dont need it to copy anymore, I just need the button to select/highlight the text within the text box

    Thanks again
    Free Thinkers Are Dangerous.

  4. #4
    Board Regular
    Join Date
    Aug 2002
    Posts
    187

    Default Re: VBA Code for a command button to copy a text boxes value

    Anyone?
    Free Thinkers Are Dangerous.

  5. #5
    Board Regular Todd Bardoni's Avatar
    Join Date
    Aug 2002
    Location
    Rochester, MI USA
    Posts
    3,044

    Default Re: VBA Code for a command button to copy a text boxes value

    Quote Originally Posted by rogersj
    I dont need it to copy anymore, I just need the button to select/highlight the text within the text box

    Thanks again
    What part of this is copying? Is there a purpose to select the text in a textbox? What do you want to do with the text after its selected?
    Todd


    "I'm a Data Anlyst(intermediate) and have no idea what it's all about."

  6. #6
    Board Regular
    Join Date
    Aug 2002
    Posts
    187

    Default Re: VBA Code for a command button to copy a text boxes value

    I just want it to select the value, to highlight it. This is for a friend of mine. I dont know why, but this is all he needs done. Thanks for the reply
    Free Thinkers Are Dangerous.

  7. #7
    Board Regular
    Join Date
    Feb 2002
    Posts
    384

    Default Re: VBA Code for a command button to copy a text boxes value

    :D

  8. #8
    Board Regular
    Join Date
    Feb 2002
    Posts
    384

    Default Re: VBA Code for a command button to copy a text boxes value

    rogersj, I believe the code below will perform as you requested. I'm not sure if all of those properties are truly necessary, but it does seem to work. Regards, Marc

    Code:
    Private Sub CommandButton1_Click()
    TextBox1.SelStart = 0       'Indicates the starting point of selected text
    TextBox1.SelLength = 500    'number of characters selected in a text box
    TextBox1.SetFocus           'Moves the focus to this instance of an object.
    TextBox1.Copy               'Copies the contents of an object to the Clipboard.
    End Sub

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com