Reputation: 191
I am trying to search an ActiveX TextBox (TextBox1) to replace a phrase with nothing...
I have this code that seems to just wipe the entire box rather than the phrase in isolation.
Private Sub CommandButton3_Click()
TextBox1 = Selection
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "This is the text to remove!"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
With some additions (like selecting all shapes in the active document)- the code works with an ordinary TextBox - and with the rest of the document too... just not the ActiveX box (which is what I want!!)
Please help!
Upvotes: 0
Views: 2365
Reputation: 13235
You can simply use the built-in VBA Replace function:
Private Sub CommandButton3_Click()
TextBox1.Value = Replace(TextBox1.Value, "This is the text to remove!", "")
End Sub
Upvotes: 2