I would like to search in a word header and footer for specific words, and then replace them with words from my database.

Currently i can search and replace words anywhere in the word document except for the header and footer.

Can anybody help me with this?

Code for normal search(that works):

```
Procedure FindAndReplace(Find,Replace:String);
Begin
      //Initialize parameters
  WrdApp.Selection.Find.ClearFormatting;
  WrdApp.Selection.Find.Text := Find;
  WrdApp.Selection.Find.Replacement.Text := Replace;
  WrdApp.Selection.Find.Forward := True;
  WrdApp.Selection.Find.Wrap := wdFindContinue;
  WrdApp.Selection.Find.Format := False;
  WrdApp.Selection.Find.MatchCase :=  False;
  WrdApp.Selection.Find.MatchWholeWord := wrfMatchCase in Flags;
  WrdApp.Selection.Find.MatchWildcards :=wrfMatchWildcards in Flags;
  WrdApp.Selection.Find.MatchSoundsLike := False;
  WrdApp.Selection.Find.MatchAllWordForms := False;
     { Perform the search}
  if wrfReplaceAll in Flags then
   WrdApp.Selection.Find.Execute(Replace := wdReplaceAll)
  else
   WrdApp.Selection.Find.Execute(Replace := wdReplaceOne);
End;

```

Code for header and footer search(doesnt work):

```
WrdApp.Selection.Find.ClearFormatting;
      WrdApp.Selection.Find.Text := 'Class';
      WrdApp.Selection.Find.Replacement.Text := grade;
      WrdApp.Selection.Find.Forward := True;
      WrdApp.Selection.Find.Wrap := wdFindContinue;
      WrdApp.Selection.Find.Format := False;
      WrdApp.Selection.Find.MatchCase :=  False;
      WrdApp.Selection.Find.MatchWholeWord := wrfMatchCase in Flags;
      WrdApp.Selection.Find.MatchWildcards :=wrfMatchWildcards in Flags;
      WrdApp.Selection.Find.MatchSoundsLike := False;
      WrdApp.Selection.Find.MatchAllWordForms := False;
     { Perform the search}
  if wrfReplaceAll in Flags then
    WrdApp.ActiveDocument.Sections.Item(1).Headers.Item(wdHeaderFooterPrimary).Range.Find.Execute(Replace := wdReplaceAll)
  else
    WrdApp.ActiveDocument.Sections.Item(1).Headers.Item(wdHeaderFooterPrimary).Range.Find.Execute(Replace := wdReplaceOne);

```