Search code examples
c#ms-wordautomationprimary-interop-assembly

Select the Header as the range to search in Microsoft Word


I have some text in the header of a Word document.

I have a find and replace method that searches for text and then replaces it if it is found.

How do I only select the header to be the range to search and replace for key words?


Solution

  • Access the header and find inside it?

    this.Doc.Sections[1].Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Find()
    

    or select the header and search the selection:

    this.Doc.Sections[1].Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Select
    Application.Select.Find()