Reputation: 995
Is there anyway to replace text in a textbox for example see below. I am currently using this, but does not seem to work well in VBA.
If TextBox6.Text.Contains("<GTOL-PERP>") Then
TextBox6.Text = TextBox6.Text.Replace("<GTOL-PERP>", "j")
End If
Upvotes: 2
Views: 25454
Reputation: 1768
.Text is a string property in VBA. Strings are not objects in VBA so you'll need to use string functions rather than methods when dealing with them. See below:
If instr(TextBox6.Text, "<GTOL-PERP>") Then
TextBox6.Text = replace(TextBox6.Text, "<GTOL-PERP>", "j")
End If
A List of String Functions in VBA
EDIT You can actually skip the IF since replace() doesn't throw an error if the text isn't in the string.
Upvotes: 6