我正在尝试编写一个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
这可能有所帮助
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