title: How to perform a selective extraction of text highlighted in yellow from an MS Word document?
body: <p>I am trying to write a VB script that extracts all text passages highlighted in yellow from a given MS Word document. My code seems >>almost&lt;&lt; to be working ... but I have not been able to restrict the text export to sections highlighted in yellow only. Please note the script has to be selective for highlight colour in case the document contains highlights in several colours.</p>
  
  <pre><code>Sub FindHighlightedText()
  
      'Get current working directory.
      Dim pwd As String
      pwd = ActiveDocument.Path
  
      Dim Name As String
      Name = pwd &amp; "\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 &amp; vbNewLine
          End If
  
      End With
  
  
      ' Close the output filehandle.
      Close #handle
  
  End Sub
  </code></pre>