开发者

How can I automatically highlight and extract colored text in MS Word?

开发者 https://www.devze.com 2023-01-09 15:18 出处:网络
I have a bunch of documents that need to be edited. The authors use blue text in some parts of the documents to indicate that those words need to be linked.

I have a bunch of documents that need to be edited. The authors use blue text in some parts of the documents to indicate that those words need to be linked.

Thank you cornelius for the highlight text code:

Sub HighlightNotBlack()
    Dim char As Range

For Each char In ActiveDocument.Characters
If cha开发者_如何学编程r.Font.Color <> wdColorAutomatic And char.Font.Color <> wdColorBlack Then
    char.HighlightColorIndex = wdYellow
End If
Next
End Sub

I would like to expand on this question. Is it possible to extract out only the highlighted text into a new word file? It should also be smart enough to know that two or more consecutive words in a sentence would all appear on one line in the new document as opposed to each word getting its own line in the new document. I figure it could look for all highlighted selections and only bring those over since the whole block of text would be entirely highlighted


I came with something like this. It highlights all non-black and non-automatic characters in active document.

Sub HighlightNotBlack()
Dim char As Range

For Each char In ActiveDocument.Characters
    If char.Font.Color <> wdColorAutomatic And char.Font.Color <> wdColorBlack Then
        char.HighlightColorIndex = wdYellow
    End If
Next
End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号