************************************************** >* Start of code >************************************************** >select * from (home()+"samples\data\customer") into cursor wrdTest >* Replace with your select for invoice >_VFP.datatoclip(alias(),reccount(),3) && Copy VFP table to clipboard >* This part is for changing headers later in word >local ix >local array aNewFieldNames[fcount()] && Will change some headers later >for ix=1 to fcount() > aNewFieldNames[ix] = field(ix) >* dbgetprop(alias()+"."+field(ix),"Field","Caption") is a shorcut >endfor >aNewFieldNames[1] = "Customer Id" >aNewFieldNames[2] = "Company Name" >aNewFieldNames[3] = "Pls Contact To" >use in "wrdTest" && No need anymore >* This part is for changing headers later in word >PUBLIC oWordDocument > >*** set the LOCALEID to English >nlLocaleId=sys(3004) && Save local id >=sys(3006,1033) && We will be sending instructions in English > >wait window nowait "Creating Word Document..." && Inform user >oWordDocument=createobject("word.basic") && Create word object > >with oWordDocument > .appshow && Show word app > .filenewdefault && New file, default template - this is our main doc > * If you have a predefined doc template > * then instead of filenewdefault - fielopen(cTemplateDoc) > .MailMergeCreateDataSource("c:\temp\xmergedoc") && Create datasource > .MailMergeEditDataSource && Edit data source > .editselectall && Select entire doc - has default fields now > .editpaste && Clipboard data pasted to word - paste over > .editfind(" ","",0,0,0,0,0,0,,1,,1) >* Remove spaces - otherwise header fail > .editselectall && Select entire doc > .texttotable(1) && Convert text to table - tabs (1) (Word table) > .editgoto("\StartOfDoc") >* Go to predefined bookmark - Start of doc > .editgoto("\Table") >* Go to predefined bookmark \Table - Start of table > .nextcell > .prevcell && .nextcell .prevcell to select first cell > for ix=1 to alen(aNewFieldNames) > .insert(aNewFieldNames[ix]) > .nextcell > endfor > .tabledeletecolumn && Delete extra column > .MailMergeEditMainDocument && Activate the main document >* Now you have "MailMerge" toolbar and at the very left "Insert Merge field tab" >* You can also insert a merge field programmatically >* .InsertMergefield("address") >endwith > >**** Set the LocaleId to the previous value >=sys(3006,val(nlLocaleId)) > >************************************************** >* End of code >**************************************************Cetin