Search code examples
ms-wordword-addins

Searching Word document from add-in


I'm finding a text that has certain style in the Word document. I know it can be done using Selection.Find but I can't find any other way how to do it.

The issue with Selection.Find is that progress of add-in is visible to the user because if something is found, it's selected, etc. Is there a way how to do it so the text isn't selected ?

Thank you


Solution

  • The Range to search can be stored in a variable and use range.Find instead of Selection.Find:

    Range range = document.Content
    
    if ( range.Find.Execute("*") ) 
    {
        Debug.Print(range.Text);
    }