0

我正在尝试编写一个 VB 脚本,从给定的 MS Word 文档中提取所有以黄色突出显示的文本段落。我的代码似乎 >> 几乎 << 正在工作......但我无法将文本导出限制为仅以黄色突出显示的部分。请注意,脚本必须选择高亮颜色,以防文档包含多种颜色的高亮显示。

Sub FindHighlightedText()

    'Get current working directory.
    Dim pwd As String
    pwd = ActiveDocument.Path

    Dim Name As String
    Name = pwd & "\Output.txt"

    ' Create a filehandle and open the output file.
    handle = FreeFile()
    Open Name For Output As #handle

    With ActiveDocument.Range.Find

        .ClearFormatting
        .Highlight = True
        .Forward = True

        'I THINK THE PROBLEM IS HERE!!
        If .Parent.HighlightColorIndex = wdYellow Then
              print #handle, .Parent.Text & vbNewLine
        End If

    End With


    ' Close the output filehandle.
    Close #handle

End Sub
4

1 回答 1

2

这可能会有所帮助

Sub Macro1()

    With Selection.Find
        .Highlight = True
        .Wrap = wdFindContinue
        .Format = True
    End With

    Do While Selection.Find.Execute()

        If Selection.Range.HighlightColorIndex = wdYellow Then
             Debug.Print Selection.Range.Text
        End If

    Loop

End Sub
于 2013-02-25T21:10:03.617 回答