Results 1 to 2 of 2

Thread: How to find highlighted text from Word file?

  1. #1
    Man
    Man is offline C# Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Mar 2017
    Posts
    1
    Rep Power
    0

    How to find highlighted text from Word file?

    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 ?

    Code:
    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

  2. #2
    jmcilhinney is offline C# Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,468
    Rep Power
    118
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •