Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何取消我刚才在Word中突出显示的文本的高亮显示_Vb.net_Ms Word - Fatal编程技术网

Vb.net 如何取消我刚才在Word中突出显示的文本的高亮显示

Vb.net 如何取消我刚才在Word中突出显示的文本的高亮显示,vb.net,ms-word,Vb.net,Ms Word,发生错误的步骤如下所述: 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 w

发生错误的步骤如下所述: 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
我正在学习使用VB.NET自动处理word。有适合初学者的教程吗,请推荐。
参考您的代码,尝试以下操作:

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
注释:有时在使用“查找>>替换”时需要添加其他参数。如果上述语法不起作用,请尝试在我在上述代码中注释的点中添加部分或全部属性:

    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False

单词。前进,。换行。。。以蓝色突出显示错误:'Forward'不是'Word.Replacement'的成员,.Wrap不是'Word.Replacement'的成员…是的,我给了您需要转换为VB.Net的VBA代码,我认为这是一个原因。