in reply to text highlight or modification.

I think that it can be very-safely said that t-h-e way to accomplish all such magickal spells, within the Microsoft Windows® environment, is OLE.   It is possible to instantiate an instance of, say, a Word.Document, and thence to reference particular segments of the same, and to do various things with them, all within a very consistent and well-thought out framework.

“It’s very slick.   Quite a Very Good Hack,™ although I freely admit that I never imagined that I would ever say such a thing about anyone-at-all from Redmond, Washington ...   Yes, it is Very Good.”