将突出显示的文本更改为不同的颜色

发布于 2024-07-08 07:40:35 字数 209 浏览 9 评论 0原文

我在 Word 2007 中制作了一些简单的 .doc 文件,其中我更改了文本颜色并使用突出显示来比较一些相似的文本。 我想做的是将绿色文本或灰色突出显示的任何实例更改为各自不同的颜色。

我确信有一种简单的方法可以使用 VBA 来完成此操作,但也欢迎任何其他类型的答案。

编辑:虽然我确实很欣赏答案,但最好是允许我将 .doc 文件保留为 .docs 的答案。

I have some simple .doc files I made in Word 2007 where I changed the text color and used highlights to compare some similar texts. What I'd like to do is change any instances of green text or gray highlighting to different respective colors for each.

I'm sure there is a simple way to do this with VBA but any other sort of answers are also welcome.

EDIT: While I do appreciate answers, one that allows me to keep the .doc files as .docs is preferred.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萌梦深 2024-07-15 07:40:36

这不是 2007 年的内容,但这个想法应该适合。 此示例将所有当前突出显示更改为新的默认突出显示 (wdBrightGreen),并将所有绿色文本更改为红色。

Sub ChangeColor
Options.DefaultHighlightColorIndex = wdBrightGreen

    Selection.Find.ClearFormatting
    Selection.Find.Highlight = True
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Highlight = True
    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting
    Selection.Find.Font.Color = wdColorBrightGreen
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Color = wdColorRed
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

This is not from 2007, but the idea should suit. This example changes any current highlight to the new default highlight (wdBrightGreen) and any green text to red.

Sub ChangeColor
Options.DefaultHighlightColorIndex = wdBrightGreen

    Selection.Find.ClearFormatting
    Selection.Find.Highlight = True
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Highlight = True
    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting
    Selection.Find.Font.Color = wdColorBrightGreen
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Color = wdColorRed
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
烟凡古楼 2024-07-15 07:40:36

您始终可以将文件另存为 HTML,并在那里替换颜色。 颜色用 表示

<span style='color:red'>...

,突出显示用 表示

<span style='background:yellow;mso-highlight:yellow'>...

如果您的文档足够简单,应该很容易操作。

编辑回答问题中的编辑:完成后,重新打开文件并将文件另存为 .doc。

You can always save the file as HTML, and replace colors there. Color is represented with

<span style='color:red'>...

and highlight is

<span style='background:yellow;mso-highlight:yellow'>...

Should be easy to manipulate if your document is simple enough.

Edit that answers the edit in the question: After you are done, re-open the file and save the file back as .doc.

秋日私语 2024-07-15 07:40:36

我认为可以突出显示彩色文本的一部分,然后从“主页”选项卡上的选择文本菜单选项中选择“选择具有相似格式的文本”选项。 然后只需选择所需的文本颜色即可。
希望这有效。

I thought one could highlight a section of the coloured text and then choose "select text with similar formatting" option from the select text menu option on the Home tab. Then just select the text colour required.
Hope this works.

醉南桥 2024-07-15 07:40:36

这应该适合您的目的:

Sub RehiliteAll()

    Const YOUR_REQUIRED_COLOR_IDX As Integer = 6 'RED'
    Dim doc As Range
    Set doc = ActiveDocument.Range

    With doc.Find
        .ClearFormatting 'resets default search options'
        .Highlight = True
        .Wrap = wdFindStop

        While .Execute

            If doc.HighlightColorIndex = YOUR_REQUIRED_COLOR_IDX Then
                doc.Select
                MsgBox doc.HighlightColorIndex
                'Do stuff here'
            End If

            'doc has been reassigned to the matching'
            'range; we do this so word keeps searching'
            'forward'
            doc.Collapse wdCollapseEnd
        Wend
    End With

    Set doc = Nothing
End Sub

'I am closing comment quotes so that SO formatting'
'does not get messed up too much.'

This should work for your purpose:

Sub RehiliteAll()

    Const YOUR_REQUIRED_COLOR_IDX As Integer = 6 'RED'
    Dim doc As Range
    Set doc = ActiveDocument.Range

    With doc.Find
        .ClearFormatting 'resets default search options'
        .Highlight = True
        .Wrap = wdFindStop

        While .Execute

            If doc.HighlightColorIndex = YOUR_REQUIRED_COLOR_IDX Then
                doc.Select
                MsgBox doc.HighlightColorIndex
                'Do stuff here'
            End If

            'doc has been reassigned to the matching'
            'range; we do this so word keeps searching'
            'forward'
            doc.Collapse wdCollapseEnd
        Wend
    End With

    Set doc = Nothing
End Sub

'I am closing comment quotes so that SO formatting'
'does not get messed up too much.'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文