【问题标题】:How to perform a selective extraction of text highlighted in yellow from an MS Word document?如何从 MS Word 文档中选择性地提取以黄色突出显示的文本?
【发布时间】:2013-02-25 19:40:00
【问题描述】:

我正在尝试编写一个 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

【问题讨论】:

  • 这和excel-vba有什么关系?
  • 不多,我同意。为错误分类道歉。

标签: vba ms-word text-formatting


【解决方案1】:

这可能会有所帮助

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 2020-02-18
    • 2016-01-11
    • 2023-03-04
    • 2023-01-31
    • 2013-10-17
    • 1970-01-01
    相关资源
    最近更新 更多