如下面的步骤所述发生错误:
1.如果我搜索某个关键字,则搜索到的关键字会被突出显示
2.下次我搜索某些内容时,前面突出显示的搜索结果仍然存在
3.如何删除我之前制作的重点
Private Sub Search_Button_Click(sender As Object, e As EventArgs) Handles Search_Button.Click
Dim wordApp As Word.Application, currentDoc As Word.Document
wordApp = DirectCast(GetObject(, "Word.Application"), Word.Application)
currentDoc = wordApp.ActiveDocument
With currentDoc.Content.Find
.MatchCase = False
.ClearFormatting()
.Text = SearchBox.Text
With .Replacement
.ClearFormatting()
.Text = SearchBox.Text
.Highlight = Word.WdColor.wdColorTurquoise
End With
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
End Sub
End Class
答案 0 :(得分:0)
尝试这样的事情(参考你的代码):
With currentDoc.Content.Find
.ClearFormatting()
.Highlight = True
With .Replacement
.ClearFormatting()
.Highlight = False
'see additional comment below to this point of the code
End With
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
评论:在使用find >> replace
时,有时需要添加其他参数。如果上面提到的语法不起作用,请尝试在我在上面的代码中评论的点中添加一些(或所有)属性:
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False