Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word Automation -- Bookmarks vs. MailMergeFields
Message
De
02/09/1998 18:22:03
Nancy Folsom
Pixel Dust Industries
Washington, États-Unis
 
 
À
02/09/1998 18:04:22
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00131232
Message ID:
00132585
Vues:
30
Peter:
I merge the data from my VFP app. So, I CREATEOBJECT a Word instance in my app and replace the mergefields with data from my fields. The following is an excerpt of my code (as usual, not commented < s > ):
LOCAL loo, cError, oDoc
_VFP.autoyield = .F.
loo = CREATEOBJECT( 'form' )  && This is a "dummy" form for holding the control
loo.ADDOBJECT( 'oObject', 'oleWord' )  
WITH loo.oObject.object.application
	oDoc = .documents.add( this.templates + 'APMM\' + oPage.oleBoundControl1.templatefilename )
	cError = ON( 'ERROR' )
	ON ERROR RETURN && MESSAGEBOX( 'Unable to initialize the document' )
	EVAL( "this." + TRIM( STRTRAN( oPage.Caption, ' ', '_' ) ) + "( loo.oObject.object.application.wordBasic )" )
	oDoc.activate()
	ON ERROR RETRY
	.wordbasic.filesaveas( TRIM( putfile( 'File Name', ;
										 TRIM( oPage.caption ) + trim( baseproj.proj_no ) + '.doc', 'doc' ) )  )
	ON ERROR &cError
	lNewDoc = .T.
	oPage.docfile.Value = oDoc.FullName
	oDoc.Close()
ENDWITH
loo.oObject.Object.Application.DisplayAlerts = 0
loo.oObject.object.application.quit()
Then, I have methods for initializing the documents. The following is an example.
LPARAMETER o_Word
o_Word.setformresult( "projectno", baseproj.proj_no )
o_Word.setformresult( "title", baseproj.projtitle )
o_Word.setformresult( "fy", baseproj.fy )
o_Word.setformresult( "remarks", baseproj.remarks )
RETURN .T.
Right now this is all hardcoded, because just figuring out the automation took so much time. But, it would be straightforward to make it generic. The trick is what will the users name the merge fields? You either need a convention or you need to give them some kind of mapping utility.

From the other direction...Opening a word object and merging database fields from Word...I can't advise you there. Surely it's possible, though.

>Nancy, the part that is confusing me is the data source. When you use mail merge fields did you have to define some data source? Or is there some way to assign values directly from VFP similar to the way a bookmark is handled.
...snip
>4) When the user picks the form letter document name from the VFP reservation system, I will select their copy of the MASSDATA table and fill the fields with the data for the current reservation.
>
>5) I will then issue the proper VBA calls to Word to merge the data and print the letter. I expect that Word will not be visible.
>
>6) I will make MASSDATA.DBF a Fox2X table and try to link it directly to Mail Marge without using ODBC. (Fuzzy on how to do this.)
>
>If you or Tim know of a better approach, please advise.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform