Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to replace data in Word document Header?
Message
From
11/11/2003 11:09:14
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
11/11/2003 10:50:56
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00848724
Message ID:
00848736
Views:
18
This message has been marked as the solution to the initial question of the thread.
>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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform