0
votes

I need to loop through the entire word document and read highlighted text so that i can search the highlighted content in my XML file and replace it with the coresponding value in the XML file.
I have figured out how to parse my XML file into DOM and search for the value i need.
I still sort of the VBA code to loop through the entire word document and read the content of highlight text so that i can do the comparing with my xml file.

2

2 Answers

1
votes

You will want to loop through all the Words in the word document and check if each word is highlighted or not.
Whe you find a highlighted word then use the code you already have to look through your list of words in XML to get the replacement and subtitude for the selected word in the document.

Here is a quick sample.

Sub GetHighlightedWords()
  Dim doc As Document
  Set doc = ActiveDocument
  Dim SelectedWord As String

  For i = 1 To doc.Range.Words.Count
    If doc.Range.Words(i).HighlightColorIndex > 0 Then
        SelectedWord = doc.Range.Words(i)
        'This is where you would go to your XML document and pickup a replacement word and subtitude it for the selected word.'
        Debug.Print SelectedWord 
    End If
  Next

End Sub
1
votes

This is the perfect solution for you. I have written this macro code and tested. http://blog.haneefputtur.com/2012/02/macro-to-extract-highlighted-words-from.html