* 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