>>Hello
>>
>>Everything working fine usng find and replace in the body of the Word document.
>>I just can not figure out the command to find the replace in the header programatically.
>>
>>Thanks
>>Mo
>
>Mo,
>You might use HeadersFooters collection to specifically serach & replace there all StoryRanges to do the replacement doc wise. ie:
>
>
>#DEFINE wdReplaceNone 0
>#DEFINE wdReplaceOne 1
>#DEFINE wdReplaceAll 2
>
>Local lcDocument
>lcDocument = 'c:\myPath\myDoc.doc'
>* Replacement settings
>Local Array arrReplace[2,2]
>arrReplace[1,1] = 'FindMe'
>arrReplace[1,2] = 'ReplaceWithMe'
>arrReplace[2,1] = 'SearchMeToo'
>arrReplace[2,2] = 'ReplaceWithAnother'
>
>Local oWord As 'Word.Application'
>oWord = Createobject('Word.Application')
>With oWord
> .Documents.Open(lcDocument)
> With .ActiveDocument
> For Each myStoryRange In .StoryRanges
> ReplaceInRange( myStoryRange, @arrReplace )
> Endfor
> myStoryRange = .Null.
> EndWith
> .Visible = .t.
> .Activate
>Endwith
>
>Function ReplaceInRange
> Lparameters toRange, taReplacements
> Local ix
> For ix=1 To Alen(taReplacements,1)
> toRange.Find.Execute(taReplacements[ix,1], ;
> .F., .T.,,,,,,, taReplacements[ix,2], wdReplaceAll)
> Endfor
>
>
>PS: Just for headers you might use :
>.ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
>
>Cetin
Hi Cetin
I just can't get this to work.
here's what I am using for the document body, which work fine
SCAN
WITH poworddoc.SELECTION.FIND
.TEXT = ALLTRIM(cCursorList.SearchFor)
.replacement.TEXT = ALLTRIM(cCursorList.ReplaceWith)
.forward = .T.
.WRAP = 1
ENDWITH
poworddoc.SELECTION.FIND.execute( , , , , , , , , , , 2)
ENDSCAN
As for the header I tried every combination with
.ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
with no success
Somehow I can not get the Find property to function for .Range
what I am doing wrong?
Thanks
Mo