Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Merge Fields Problems
Message
From
05/08/2004 18:11:09
 
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
00856039
Message ID:
00931165
Views:
25
Copy this code to a prg and run... Syntax seems to work for me under Word 2000,XP and 2003.
oword=crea('word.application')
oword.visible=.t.
oword.documents.open('C:\MYFILE.doc')
oword.APPLICATION.activedocument.mailmerge.OpenDataSource('c:\MYFILE.xls',,,.T.,,,,,,,,"Entire Spreadsheet") 
Another thing I am doing is having a template document file already created on the customer machine. If c:\myfile.doc does not exist, my program just copies the template doc to the new document name before this code runs...
Then, the code will open the datasource specified using a pre-built 'word-merge' document.



>I used this kind of code
>
>*----------- OFFICE 2000 -----------*
>.objName.ActiveDocument.MailMerge.OpenDataSource("C:\MyFile.xls", 0, .F., .F., .T., .F., "", "", .F., "", "", "Entire SpreadSheet", "", "")
>
>*----------- OFFICE XP -----------*
>.objName.ActiveDocument.MailMerge.OpenDataSource2000("C:\MyFile.xls", 1, .F., .F., .T., .F., "", "", .F., "", "", "", ;
> "SELECT * FROM `MyFile$`", "")
>
>
>>>Hi Michel
>>>
>>>I am working with a similar problem today, trying to automate the opendatasource() command to link with an excel file. (office 2003)
>>>
>>>I am using VFP 8.0 SP1.
>>>
>>>Were you able to come up with the correct syntax to make this operate correctly?
>>>
>>>I am struggling a bit with this one myself...
>>>
>>>
>>>
>>>I didn't see any replies to your message, sorry to reply with a question.
>>>
>>>
>>>>In a VFP procedure, I merge a Word document with an Excel data source.
>>>>
>>>>In my Word document, I put some merge fields in the header and the footer.
>>>>
>>>>It works fine with VFP7/8 and Office XP.
>>>>
>>>>With Office 2003, the merge fileds in the header and the footer do not merge.
>>>>
>>>>In the final document, they look like the merge fields expressions (i.e. «CompanyName» instead of the name in the database).
>>>>
>>>>However when I open the Word document and I merge it manually with the same Excel data source, it works fine.
>>>>
>>>>the command line to open the Excel data source I used is :
>>>>OpenDataSource("C:\FOLDER\EXCELSOURCE.XLS", 1, .F., .F., .T., .F., "", "", .F., "", "", "", "SELECT * FROM `EXCELSOURCE$`", "")
>>>>
>>>>Thanks in advance for your help.
>>>>
>>>>Stéphan Laporte
>>>>slaporte@analystik.ca
>>
>>
>>I was able to get my merge to work in office 2003 with an excel datasource. I do not know how to avoid the confirmation message about the datasource when the file is opened...
>>
>>I used part of your code in my example - thanks...
>>
>>Example of the code that works in office 2003:
>>
>>
>>oword=crea('word.application')
>>oword.visible=.t.
>>oword.documents.open('c:\ubs_vfp\source\mcustomer_notice.doc')
>>oword.APPLICATION.activedocument.mailmerge.OpenDataSource('c:\ubs_vfp\source\mcustomer_notice.xls',,,.T.,,,,,,,,"Entire Spreadsheet")
>>
>>
Thanks,

Stacy



Black Mountain Software, Inc.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform