Your code show nothing relative to colors. And, Word has absolutely no way to know if a text represents code or something else. In word a colored text is nothing more, or less, than a black test. It is just a color. Word cannot make any difference between a thesis, a receipe or a programm unless you provide a programm to do it,
You should look to Range.Font and not range.text.
Range.Font Property (Microsoft.Office.Interop.Word) | Microsoft Learn[
^]
Font Interface (Microsoft.Office.Interop.Word) | Microsoft Learn[
^]
But you may (should) use Word macro recorder to help you. You will get a Visual Basic for Application code. With VBA you will get one or more procedures with correct word classes, methods and properties. And you can easily copy-paste text from VBA editor to VS editor.You will need to adapt (mostly combine) them with Interop.word Namespace. But with Word macro recorder you cannot use mouse inside the document. All operations in document must be do with Keyboard.
And, If you add interop.word dll as a reference in your VS Project, you will get Intellisense information.