Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Automation
Message
 
 
To
01/08/2007 21:52:21
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Miscellaneous
Thread ID:
01239546
Message ID:
01245355
Views:
35
>BACKGROUND:
>
>I have a web application where users can request print merges to be produced. Requests are placed in a queue table, later read by a listner which creates the data as an excel document. Using word automation the listner opens the template and attaches the excel file as a datasource.
>
>THE PROBLEM:
>
>The template documents were designed by my users to work with an excel document with unwieldly field names. I have converted the data into foxpro and attempted to modify the templates to reflect the changes. Problem is ANY inconsistencies bring down the whole listner when the automation object trys to excecute the print merge.
>
>MY SOLUTION: Code below
>
>A programmatic check for consistency between the word document and the excel data. I am utilizing a couple of collections in the word document object to check the document just before the mail merge execution.
>
>* field names in the data source
>oWord.ActiveDocument.MailMerge.datasource.FieldNames
>
>* fields in the word template
>oWord.ActiveDocument.fields.item(m.i).select
>
>NOTES:
>
>The frustrating thing about the document object's fields collection, is the lack of a property with the name of the field, that I found. I selected the merge field and copied the clipboard to get at the field name. That isn't so hard, but it wasn't exactly intuitive. :)
>
>Some of my word templates had merge fields in text boxes, footers and headers. Turns out those do not show up in the document's fields collection, so I had to work around that issue.
>
>Carole Shaw

<snip>

Thanks for sharing the code. I think it may be a good idea to also create a WiKi document for it.

Thanks again.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform