Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mail Merge of Word 2003
Message
From
04/05/2004 09:49:17
 
 
To
15/04/2004 15:31:06
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00895297
Message ID:
00900686
Views:
28
This message has been marked as the solution to the initial question of the thread.
Hi,
I had to change my mailmerge code with Office 2003.
In the past, I could open a MS Word DOC and connect it to
a mailmerge source and then save the DOC. It would remember
the connection when I performed a VFP call to it to merge.
With Office 2003 which has Word 2003, it no longer remembered.
So, my mailmerge code now tell MS Word which data source to use.
See the following example.
Terry :)
* Procedure:	Mailmerge_preview
* Description:	Do a mailmerge to Microsoft Word
* Parameter:	tcWordDoc: Required: The Word document to use as the merge template.
*                             A XLS file is used for the merge.
*                             The XLS must have the same name as the Word Doc.


* Example of a "CALL" to this routine:
*     DO Mailmerge_preview WITH "C:\MY_DOCS\FORM_LETTER.DOC"

LPARAMETERS tcWordDoc

LOCAL oWord, oDocument, oMerge, oFormLetter, lnWkArea, llRetVal, xlsmv

* Note, "tcWordDoc" comes with the file extention of "DOC".

* Create a complete XLS file name based on the Word DOC.
STORE STRTRAN(tcWordDoc, ".DOC", ".XLS") TO xlsmv

llRetVal = .T.

oWord = CREATEOBJECT("Word.Application")

* This was added to prevent the "Server threw an Exception" error
*    on some Win XP / Office XP computers.
WAIT " " TIMEOUT .8

* oWord.Documents.Open(("A:\APPR.DOC"), .F., .F., .F., "", "", .F., "", "", 0)

* oWord.Documents.Open((SYS(5) + SYS(2003) + "\FORM_LETTER1B_FAIL.DOC"), .....

oWord.Documents.Open((tcWordDoc), .F., .F., .F., "", "", .F., "", "", 0)
oFormLetter = oWord.ActiveDocument
oWord.ActiveDocument.MailMerge.OpenDataSource((xlsmv))

WITH oWord.ActiveDocument.MailMerge
	.Destination = 0
	.MailAsAttachment = .F.
	.MailAddressFieldName = ""
	.MailSubject = ""
	.SuppressBlankLines = .F.
	WITH .DataSource
		.FirstRecord = 1
		.LastRecord = -16
	ENDWITH
	.Execute(.T.)
ENDWITH

* Close Form Letter Template and clean up files...
oFormLetter.Close(0)
* oWord.Quit(0)
oWord = .NULL.
RELEASE oWord
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform