title: Searching EVERY header in a Word document, using Excel VBA?
body: <p>So I have the (incredibly ugly) code below, which I need to use to open a specified word document, search for a certain value in the header of every page, and then print the page on which it is found.</p>
  
  <p>My problem is that currently it only searches the first page as the document is opened, but there are about 400 pages per document that needs searching.</p>
  
  <pre><code>Private Sub CommandButton1_Click()
      Dim i As Integer
      i = 2
      Do While Cells(i, 1).Value &lt;&gt; ""
          Set wdApp = CreateObject("Word.Application")
          wdApp.Visible = True
          wdApp.documents.Open ("\\Location" &amp; Cells(i, 9) &amp; ".docx")
  
          Dim Sctn As Section, HdFt As HeadersFooters
          Dim FindWord As String
          FindWord = Cells(i, 11).Value
  
          wdApp.Selection.WholeStory
          wdApp.Selection.Find.ClearFormatting
  
          For Each Sctn In wdApp.ActiveDocument.Sections
              For Each HdFt In Sctn.Headers(wdHeaderFooterPrimary)
                  With wdApp.Selection.Find          
                      .Text = FindWord
                      .Forward = True
                      .Wrap = wdFindContinue
                      .Format = False
                      .MatchCase = False
                      .MatchWholeWord = True
                      .MatchWildcards = False
                      .MatchSoundsLike = False
                      .MatchAllWordForms = False
  
                      If .Execute Then
                          Cells(i, 12).Value = "Yes"
                      Else
                          Cells(i, 12).Value = "No"
                      End If
                  End With
              Next
          Next
          wdApp.Quit
  
          i = i + 1
      Loop
  End Sub
  </code></pre>
  
  <p>I currently have it telling me 'yes' or 'no' for whether the data has been located, to save on printing.</p>
  
  <p>I would be extremely grateful for any help you are able to provide, or pointers.</p>