Using the Word Interop API I have a document from which I remove text that have been highlighted with a specific color. Boiled down, the logic is similar to this:
if(range.HighlightColorIndex == WdColorIndex.wdYellow)
{
range.Delete();
}
For some documents I have noticed that range.HighlightColorIndex returns the value: 999999.
By taking a look the WdColorIndex enum (which is the type of the HighlightColorIndex property), I see the enum is implemented with elements assigned a value in the interval from -1 to 16, which doesn’t explain the 999999 number returned.
Further, by using Word, I have noticed some odd behavior. Creating a new document with two yellow-highlighted lines – the first containing text and a hyperlink and the second containing just text:
- Before the document has been saved and closed for the first time, Word do recognize each line as being highlighted with a yellow color when selecting them one-by-one.
- After the document has been saved, closed, and re-opened, Word no longer recognizes the line with text and a hyperlink as being highlighted, whereas the line with only text is still recognized as being highlighted.
A screenshot of Word’s highlight recognition after opening the document is seen here:

From this study, it seems that this might be a bug in Word, but I want to be sure that I’m not missing something here – so, basically, does anybody know if this is intended behavior or a bug, and further, what a reasonable approach would be to deal with it when using Word Interop in the given case?
For this scenario, I’m running Office 2010 and version 14 of the Word Interop API.
The value of 999999 is used by Word to indicate that the current selection contains more than one of the respective formatting.
In your example, the hyperlink is represented as a Word field (press Alt-F9 to toggle the code view) which contains a highlighted run. The field itself does not have highlighting applied after the document is re-opened. This is not necessarily a bug in Word, it’s just the behavior of (hyperlink) fields not to remember the formatting on the field level as such.
However, your actual task seems to be to remove highlighted text from a document. This can usually be better done using the
Range.Findobject of Word:Here is a complete sample program that you can use to remove highlight: