我正在尝试搜索ActiveX TextBox(TextBox1)以替换没有任何内容的短语......
我有这个代码似乎只是擦除整个框而不是孤立的短语。
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
添加一些内容(比如选择活动文档中的所有形状) - 代码可以使用普通的TextBox - 还可以使用文档的其余部分...而不是ActiveX框(这就是我想要的!!)
请帮忙!
答案 0 :(得分:2)
您只需使用内置VBA Replace function:
即可Private Sub CommandButton3_Click()
TextBox1.Value = Replace(TextBox1.Value, "This is the text to remove!", "")
End Sub