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