Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word Manipulation Through VFP
Message
De
07/08/1998 10:01:13
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00124749
Message ID:
00124762
Vues:
96
>While I was working on doing a mail merge through VFP I ran across a problem. I can do a merge if I go in to the Word template and manually set the data source. I would however like to create the data source 'on the fly' through VFP. I know I can do this by using the oWord.MailMergeOpenDataSource("source.dbf") command however it pops up a window in Word that asks to confirm whether data source is Foxpro or Dbase ODBC. Is there someway to pass this information from VFP so that it doesn't pop that dialog box up to the user? Also does anyone know the command to select different documents in Word. I want to close the templates after I do the merge so that only the form letter is left.
>
>Thanks in advance!
Kevin,
Check Mailmerge class in files\classes section and example below that merges to a doc or printer.
**************************************************
* Start of code
**************************************************

PUBLIC oWordDocument

*** set the LOCALEID to English
nlLocaleId=sys(3004)		&& Save local id
=sys(3006,1033)				&& We will be sending instructions in English 
wait window nowait "Creating Word Document..."     && Inform user
oWordDocument=createobject("word.basic")	&& Create word object
with oWordDocument
* Remove the rem if you want the user see what's going on in word
	.appshow							&& Show word app - Word 7.0 support
	.filenewdefault        				&& New file, default template - Will create datasource
	cDSN = "DSN=Visual FoxPro Tables;UID=;PWD=;"
	cSourceDb = "SourceDB=C:\Program Files\vfp50\SAMPLES\DATA\Testdata.dbc"
	cSourceType = ";SourceType=DBC;"
	cOther = "Exclusive=No;BackgroundFetch=No;Collate=Machine;"

	cSQLStatement = "SELECT recno() as rcno,* FROM customer"

* Insertdatabase parms build here for clarifying
* 35,511 are autoformatting options for grid - ignore
* 0 Link to source false

	.InsertDatabase(35,511,0, ;
		cDSN+cSourceDb+cSourceType+cOther, ;
		cSQLStatement,,,,,,,1)

	.filesaveas("c:\temp\xxmmergedoc",0)			&& Save as a word doc for mailmerge
	.fileclose(1)						&& Close saving
* Datasource ready, now create mailmerge main document
   * If you have a document template with logo in header&footer etc use it else .filenewdefault
	.filenew("c:\temp\prttest.doc")     && New file based on prttest (Logo in header - address in footer)
	* This needs template file already EXISTS !
	* Just create "c:\temp\prttest.doc" for testing
	.MailMergeOpenDataSource("xxmmergedoc.doc")  && Set saved file as data source for mailmerge (Directly a table could be set via ODBC)
	.MailMergeEditMainDocument			&& Activate the main document
	.insertmergefield("rcno")
	.insertpara
	.Insert("Dear ")                    && Start writing
	.InsertMergeField("Contact")        && Insert a merge field - any field in data table
	.Insert(",")
	.InsertPara							&& Or +chr(13) to previous
	.Insert("...Some text here...")
	.InsertPara
	.Insert("Thanks.")
	.InsertPara
	.Insert("Yours sincerely")
	.InsertPara
	.InsertPara
	* Instead of these inserts template could hold the formatted text and 
	* mark the mergefield places with bookmarks
	* or totally preset template doc could there be
	*	.editbookmark("Contact",,,,1) && Goto bookmark
	*	.InsertMergeField("Contact")
	*
	* Following address is fictional (Tel. is mine)
	.insert("6200 Science Fiction Street"+chr(13))
	.insert("Somecity, AR 80111"+chr(13))
	.insert("TEL: (+90) 232-278 50 83  FAX: (+90) 232-278 50 82"+chr(13))
 .MailMergeToDoc       && Merge to a new document - For printer .MailMergeToPrinter
* .FileSaveAs("c:\temp\frmletters.doc") && If want to save
*	.MailMergeToPrinter
*	.Fileexit(2)   && Exit no save - directly print and exit w/o save
endwith
* InsertWordField could also be used but FP is more capable of it so we should have transfered the needed already
* Here the control is passed to word. Sitting and waiting for further process.
wait window "Data Merged to c:\temp\frmletters.doc"

**** Set the LocaleId to the previous value
=sys(3006,val(nlLocaleId))

**************************************************
* End of code
**************************************************
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform