Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word 2003 automation Problem
Message
From
13/05/2004 18:39:07
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00902166
Message ID:
00903881
Views:
30
Hi Gerard,
Sorry I've been quite busy nowadays, finally project got out of door.
Here is a sample doing it creating and using a doc as the source :
#include "wdconst.h"
Select * ;
	from (_samples+'data\customer') ;
	where country = 'USA' ;
	into Cursor Tempreport

lcTemp = Sys(2015)+'.tmp'
lnFields = Fcount()
Copy To (lcTemp) Type Delimited With "" With Tab
lcHeader = ''
For ix = 1 To Fcount()
	lcHeader = lcHeader + Iif(Empty(m.lcHeader),'',Chr(9)) + ;
		'A_long_header_for_field_'+Field(m.ix)+'_here'
Endfor

lcSourceDoc = 'c:\temp\Source.txt'
Strtofile(m.lcHeader+Chr(13)+Chr(10)+;
	Filetostr(m.lcTemp),m.lcSourceDoc)
Erase (m.lcTemp)

*** set the LOCALEID to English
nlLocaleId=Sys(3004)  && Save local id
=Sys(3006,1033)       && We will be sending instructions in English
*** set the LOCALEID to English

Local oWordDocument, llToPrinter, lcTempDataDoc
oWord=Createobject("word.application")	&& Create word object
With oWord
	.documents.Add  && New file or open a template
	With .Activedocument.Mailmerge
          *
          * Set file as data source for mailmerge
          * File is a tab delimited text file with header line
          * Since word's default settings perfectly fit
          * opening a tab delimited file as if it were a table
          * this is just we want - no need for a conversion
          *
          * Or thinking any Word owner should also have Excel 
          * (not true always) you might open the text file with
          * Excel and set that as a datasource
          *
          .OpenDataSource(m.lcSourceDoc) 
	  .EditMainDocument	&& Activate the main document
	Endwith
	.Application.Selection.TypeText("Dear,"+Chr(13))
	With .Application.Selection.Font
		.Name = 'Times New Roman'
		.Italic = .T.
		.Size = 14
	Endwith
	.Activedocument.Mailmerge.Fields.Add(.Application.Selection.Range, ;
   'A_long_header_for_field_Contact_here')
	.Application.Selection.TypeText(Chr(13))
	.Activedocument.Mailmerge.Fields.Add(.Application.Selection.Range, ;
   'A_long_header_for_field_Company_here')
	With .Application.Selection.Font
		.Italic = .F.
		.Name = 'Arial'
		.Size = 10
	Endwith
	.Visible = .T.  && Show word app
	.Activate  && Make it the active foreground app
Endwith

**** Set the LocaleId to the previous value
=Sys(3006,Val(nlLocaleId))
As you see this is a sample to OpenDataSource BUT using an office friendly source which is simply another word doc (and word already knows how to open a txt file, simple and fast).
PS:
With oWord
	.documents.Add  && New file or open a template
If you instead write :
With oWord
	.documents.Add("c:\myPath\MyTemplate.doc")
You'd be using a presaved template.

Cetin

>Hi Cetin.
>
>I sort of thought your 'Set Flamesuit' was a joke....but you never know !!!
>
>I dont have any love for OpenDatSource,but is there another way of driving Word Mailmerge 2003 from VFP without it.
>
>Regards,
>
>Gerard
Ç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