Consulting

Results 1 to 3 of 3

Thread: Textbox1.text = Textbox1.text - "Hello"

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Arrow Textbox1.text = Textbox1.text - "Hello"

    Ive got the above code so it adds "Hello" to the text in the textbox, but what is the opposite to this, that will allow me to take out the word "Hello"?

    Ive tried Textbox1.text = Textbox1.text - "Hello" but it doesnt work

    I do not want Textbox1.text = " " because i do not want to clear the rest of the text in the box, just the word hello. thanks alot.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    Carl,

    Giving a sensible answer is difficult if we don't really know what your overall objective is.

    [VBA]Option Explicit
    Private Sub CommandButton1_Click()
    'Append text
    ActiveDocument.Variables("originalText").Value = Me.TextBox1.Text
    Me.TextBox1.Text = Me.TextBox1.Text & " Hello"
    End Sub
    Private Sub CommandButton2_Click()
    'Restore text
    Me.TextBox1.Text = ActiveDocument.Variables("originalText").Value
    End Sub
    Private Sub UserForm_Initialize()
    Me.TextBox1.Text = "Some text original text"
    End Sub
    [/VBA]

    Quote Originally Posted by carlbowles10
    Ive got the above code so it adds "Hello" to the text in the textbox, but what is the opposite to this, that will allow me to take out the word "Hello"?

    Ive tried Textbox1.text = Textbox1.text - "Hello" but it doesnt work

    I do not want Textbox1.text = " " because i do not want to clear the rest of the text in the box, just the word hello. thanks alot.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Look at the Replace function...
    Textbox1.Text = Replace(Textbox1.Text, "Hello", "")

Posting Permissions

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