How to find highlighted text from Word file?

Man

New member
Joined
Mar 20, 2017
Messages
1
Programming Experience
1-3
I found this example in VBA to find highlighted text but is it possible to be done in C# without using Microsoft.office.interop.word ?

C#:
Sub TestFind()

  Dim myRange As Range

  Set myRange = ActiveDocument.Content    '    search entire document

  With myRange.Find

    .Highlight = True

    Do While .Execute = True     '   loop while highlighted text is found

      Debug.Print myRange.Text   '   myRange is changed to contain the found text

    Loop

  End With

End Sub
 
If you want to work with DOCX files then you can use the Open XML SDK but if you want to work with DOC files then you don't have much choice but to use Office Automation. You may be able to find a third-party component that will do it but that would likely use Office Automation too and will not be free, whether it does or not.
 
Back
Top Bottom