Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to replace data in Word document Header?
Message
From
12/11/2003 12:28:52
 
 
To
11/11/2003 11:09:14
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00848724
Message ID:
00849158
Views:
27
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform