Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best way to call Word with form letter from VFP ?
Message
De
11/07/1998 12:57:14
 
 
À
11/07/1998 12:11:04
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00116476
Message ID:
00116492
Vues:
16
>In both DataFlex and FP 2.X I have used a form
>letter system where the user creates an Ascii file
>and embeds references to program variables in angle
>brackets:
>
>******************************************************
>{(8U}{(s1p20v0s3b4148T} {&a12L}
>
> Rental Services
>{(8U}{(s1p12v0s0b4101T}
>
>< N.NAME >
>< N.ADDR1 >
>< N.ADDR2 >
>< N.CITY >, < N.STATE > < N.ZIP >
>< N.NOTE >
>
>< LETTER_DATE >
>
>Thank you for making reservations with us...
>
>*****************************************************
>(I added the blanks after the carets to avoid
>confusing the HTML.)
>
>There was also embedded PCL code as you can see.
>
>This approach worked very well because the user
>could create many new form letters without ever
>talking to me.
>
>I have not been able to get the embedded PCL
>approach to work with Windows 95 so I am considering
>abandoning this approach and using WORD, possible
>with OLE.
>
>Does anyone know of a way to achieve the same end
>result: new form letters can be created without changing
>the VFP program?
>
>Peter Robinson


I wrote something almost exactly like this for a client a few months ago. Basically, the program opens a word document specified by the user, and searches it for any bookmarks with the same name as a set of fields I made available. IF the bookmarks are found, they are replaced with the current values of those fields.

Here is some simplified code:
oWord.fileopen(filename) && Open the specified form letter
bmcount = oWord.countbookmarks() && Get the number of bookmarks in the document

IF bmcount > 0
	FOR i = 1 TO bmcount
		cbookmarkname = oWord.bookmarkname(i)
		IF TYPE((cbookmarkname)) <> "U" then && If the name of the bookmark has a corresponding field name.
			DO CASE
				CASE TYPE((cbookmarkname)) = "C" OR TYPE((cbookmarkname)) = "M" &&Character or Memo
					fieldvalue = ALLTRIM(EVAL(cbookmarkname))
				CASE TYPE((cbookmarkname)) = "N" &&Numeric
					fieldvalue = ALLTRIM(STR(EVAL(cbookmarkname)))
				CASE TYPE((cbookmarkname)) = "D" &&Date
					fieldvalue = DTOC(EVAL(cbookmarkname)) && This is a good place to provide for other data types.
			ENDCASE
			oWord.editbookmark(cbookmarkname,,,,1) && Goto bookmark
			oWord.INSERT(fieldvalue) &&Insert value from table
		ENDIF
	ENDFOR
ELSE
lanswer=MESSAGEBOX(INVALID_DOC_LOC,0,APP_NAME_LOC)
	IF lanswer = 6 &&Yes
&& Form Letter Instructions  here
	ENDIF
ENDIF
This is assuming you have already opened and gotten a reference to Word using
oWord = GETOBJECT('','Word.Basic')

I hope this is enough to get you started, and let me know if you have any further questions.
Erik Moore
Clientelligence
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform