Mike,
Not sure this is perfect, but this is what I do. It gets all of the headers, footers and any text blocks within the specified "section" of the document. A section break in Word is what seperates the individual letters in a mail merge. The .ReplaceRange() method does the search and replace.
losection=this.odocument.sections[this.odocument.sections.count]
IF varTYPE(losection)='O'
this.replacerange(losection.range)
WITH losection
IF TYPE('losection.range.shaperange')='O'
lntotal=.Range.ShapeRange.count
FOR lncnt=1 TO lntotal
lorange= .Range.ShapeRange.Item[lncnt]
IF varTYPE(lorange)='O'
lorange=lorange.TextFrame.TextRange
IF varTYPE(lorange)='O'
this.replacerange(lorange)
endif
endif
endfor
ENDIF
IF TYPE('losection.footers')='O'
lntotal=.footers.count
FOR lncnt=1 TO lntotal
lorange=.footers[lncnt].range
IF varTYPE(lorange)='O'
this.replacerange(lorange)
endif
endfor
ENDIF
IF TYPE('losection.headers')='O'
lntotal=.headers.count
FOR lncnt=1 TO lntotal
lorange=.headers[lncnt].range
IF varTYPE(lorange)='O'
this.replacerange(lorange)
endif
endfor
ENDIF
ENDWITH
losection=this.odocument.sections[1]
losection.range.select
ENDIF
>Hi
>
>I must do find and replace using OLE automation with Word. I have some code who is working but just in the body of the document. I am not able to find and replace in header and footer. I need to make word search in the whole document including header and footer.
>
>Here is a sample of my code.
>
> LOCAL oWord AS "Word.Application"
> IF TYPE("oWord") <> "O"
> oWord = CREATEOBJECT("Word.Application")
> ENDIF
> oWord.Documents.Open("d:\transit2.doc")
> oWord.VISIBLE = .t.
> loSelection = oWord.ActiveWindow.ActivePane.SELECTION
> loSelection.FIND.ClearFormatting()
>
> WITH loSelection.FIND
> .TEXT = "@Transit"
> .Replacement.TEXT = "81599999"
> .Forward = .T.
> .FORMAT = .F.
> .MatchCase = .F.
> .MatchWholeWord = .F.
> .MatchWildcards = .F.
> .MatchSoundsLike = .F.
> .MatchAllWordForms = .F.
> ENDWITH
> loSelection.FIND.Execute(,,,,,,,,,,2)
>
>Thanks
>
>Mike