Changing the contents of a text box change (Text1.Text = &qu

Satal Keto

New Member
Joined
Nov 21, 2005
Messages
12
I know that i can change the text in a text box by using something like this...
Code:
Private Sub CommandButton1_Click()
TextBox1.Text = "Hello World"
End Sub

If i change the information in the text box to
Hello World 2

Is there any way of getting the CommandButton1_click() to change so that it would come up with that when i pressed on say CommandButton2?

Is there anyway at the same time to change special characters (like ") into their Chr representations (& Chr(34) &)
And where the enter key has been used "& Chr(10) &" ?

Thanks alot for any help in advance
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
If you want to change the first line of the CommandButton1_Change procedure, set a reference to "Microsoft Visual Basic for Applications Extensibilty 5.3" and try this code:

Code:
Private Sub CommandButton2_Click()
    With ThisWorkbook.VBProject.VBComponents("UserForm1").CodeModule
        .ReplaceLine .ProcBodyLine("CommandButton1_Click", vbext_pk_Proc) + 1, vbTab & "TextBox1.Text = """ & TextBox1.Text & """"
    End With
End Sub

You can use the Asc function to get the ASCII code of a character. Example:

Code:
Sub Test()
    MsgBox Asc("""")
End Sub
 
Upvote 0
Sorry im not very good at explaining what i say, Ok what i mean is...
when i press CommandButton1 it puts the text "hello world" in Text1.
If i change the text in Text1 to say "hello world 2", is there a way of getting the information saved so that next time i press CommandButton1 for it to put the text "hello world 2" in Text1.

So using code (as much as possible) changing this
Code:
Private Sub CommandButton1_Click()
Text1.Text = "hello world"
End Sub

into ....
Code:
Private Sub CommandButton1_Click()
Text1.Text = "hello world 2"
End Sub
*where hello world 2 is the text which was in Text1

Sorry i meant with the replacing characters that it was done at the same time as the text in Text1 being put into CommandButton1_Click(), as the text in Text1 would be over a couple of lines
 
Upvote 0
Sorry i miss understood what you put and thought you thought i was talking about something else.

This is what i get
Run-time error '1004':
Programmatic access to Visual Basic Project is not trusted
 
Upvote 0
Thanks that got rid of the 1004 error (although now im getting a 9 error "subscript out of range)
But thanks alot for trying to help :D
 
Upvote 0
Satal Keto said:
Thanks that got rid of the 1004 error (although now im getting a 9 error "subscript out of range)
But thanks alot for trying to help :D

Is the error on this line?

With ThisWorkbook.VBProject.VBComponents("UserForm1").CodeModule

Change the UserForm reference if your is not named UserForm1.
 
Upvote 0

Forum statistics

Threads
1,212,046
Messages
6,105,585
Members
447,972
Latest member
carrieann

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top