vb.net highlight text in word

百般思念 提交于 2019-12-13 05:17:27

问题


I am using VB.NET in VS 2012 Express to automate Word 2010. I am trying to find a string and then highlight it in Turquoise. My code works to find and highlight it, but it does it in the default yellow color. How can I change that to the desired color?

I apologize if this is a silly question, I am teaching myself VB by writing this.

For x As Integer = 0 To (dateConnected.Count() - 1)

    With oRng.Find
        .MatchCase = False
        .ClearFormatting()
        .Text = dateConnected(x)

        With .Replacement
             .ClearFormatting()
             .Text = dateConnected(x)
             .Highlight = Word.WdColor.wdColorTurquoise
        End With
       .Execute(Replace:=Word.WdReplace.wdReplaceAll)
    End With
Next

回答1:


the Highlight property accept true or false, the color index is determined by the DefaultHighlightColorIndex property, Which member Option property of application instance.

code:

 ApplicationInstant.Options.DefaultHighlightColorIndex = Word.WdColorIndex.wdTurquoise
 .Highlight = True


来源:https://stackoverflow.com/questions/19139452/vb-net-highlight-text-in-word

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!