Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Merge Help...
Message
From
28/01/2008 15:10:41
Chris Sund
Silhouette Solutions
Utah, United States
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Title:
Word Merge Help...
Miscellaneous
Thread ID:
01286305
Message ID:
01286305
Views:
114
Hello,

There are many posts out there on this, but I haven't found one that answers my questions. This is the first time I've tried to merge data to word so my questions may be simple. Keep in mind I'm using word 2007, but my users may be using 2003 or 2007.

1.) Do I have to write different code to accomodate word 2007 vs 2003?
2.) Do I create the merge document in word, and point it to an xls data source, then recreate that xls data file each time I run the document? This means I will have to distribute the word docs with my app. I'm hoping I can create them on the fly.


I found some sample code out there, and it works kind of. It will bring up my document with the proper merge fields. If I try to use the merge toolbar in word however to "Preview Results" and look at my fields merged, it doesn't work. I don't get an error, it just doesn't preview. If I add *oDoc.MailMerge.Execute to the end of my prg then everything merges, but it brings up a second word window that says "Form letters1".

Here's the sample code I've tried to adapt to. Any help is appreciated!

Chris
strConnection = [Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=C:\MyExcel.xls;DefaultDir=c:\mypath;] &&& Not sure if I need this


#DEFINE wdMainAndDataSource 2
#DEFINE wdSendToPrinter 2
#DEFINE wdDoNotSaveChanges 0
#DEFINE wdWindowStateMinimize 2

SET SAFETY OFF

CD C:\VPMAPPS\TLP

OPEN DATABASE ATLP_V SHARED

SELECT * FROM property_v WHERE .t. INTO CURSOR t1
jprop_key=t1.cprop_pk

Select;
 cprimary_owner as OwnerName,;
cname2,;
cname3,;
cco_line as CareOfName,;
caddress_b as Address,;
ccity_a as City,;
cstate_b as StateOrProvince,;
czip_a as PostalCode,;
cname as CountyName,;
caddress_c as CountyAddress1,;
ccity_b as CountyCity,;
cstate_c as CountyState,;
czip_b as CountyZip,;
cphone_b as TreasurerPhone,;
ctownship as TownshipRange,;
csection as Section,;
nparcel_no as ParcelNumber,;
MLINE(clgl_desc,1,254) as LGL_DESC,;
MLINE(cgeocode,1,254) as Geocode;
 From property_v Where cprop_pk=jprop_key And .T. Into Cursor npa

 
 COPY TO 1-NOTICE_OF_PENDING_ASSIGNMENT.XLS TYPE XL5




oWord = CREATEOBJECT("Word.Application")
oWord.Visible = .T.


oDoc = oWord.Documents.Open("C:\VPMAPPS\TLP\1 - NOTICE OF PENDING ASSIGNMENT.doc")
	oDoc.MailMerge.MainDocumentType = 0
	oDoc.MailMerge.OpenDataSource("c:\Vpmapps\tlp\1-NOTICE_OF_PENDING_ASSIGNMENT.XLS",,,,,,,,,,,"Entire Spreadsheet",,,,8)
	
	oDoc.MailMerge.DataSource.FirstRecord =  oDoc.MailMerge.DataSource.ActiveRecord
	   oDoc.MailMerge.DataSource.LastRecord = oDoc.MailMerge.DataSource.ActiveRecord
	   oDoc.MailMerge.Execute

	
Next
Reply
Map
View

Click here to load this message in the networking platform