2013-02-21 67 views
0

我试图寻找一个ActiveX文本框(TextBox1中),以取代任何一个短语...如何搜索和文本框的ActiveX替换文本

我有这样的代码,似乎刚擦了整个盒子,而不是这句话是孤立的。

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 

对于一些添加剂(如选择各种形状的活动文档中) - 该代码可与普通的文本框 - ,并与文档的其余部分太...只是没有该ActiveX箱(这是我想要!!)

请帮忙!

+1

你张贴在'TextBox1'不会改变文本的所有代码。它会查找并替换文档正文中的文本。 – 2013-02-21 17:38:22

回答

2

您可以简单地使用内置的VBA Replace function

Private Sub CommandButton3_Click() 
    TextBox1.Value = Replace(TextBox1.Value, "This is the text to remove!", "") 
End Sub 
+0

非常感谢你 - 压力重重! – stilts77 2013-02-22 09:51:03