Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word Automation -- Bookmarks vs. MailMergeFields
Message
 
 
À
29/08/1998 01:46:30
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00131232
Message ID:
00131326
Vues:
29
>In a recent thread, there was a discussion between John Harvey, Garrett Fitzgerald, and Nancy Folsom regarding the various merits of Bookmarks vs. MailMergeFields. Garrett and Nancy prefer the MailMergeFields because they are visible and more easily manipulated by end users. John uses bookmarks because he prepares the template documents and doesn't want them edited. I would like to follow up this discussion with some newbie type questions:
>
>1) What is the best way to insert MailMergeFields? I get confused by the fact that they seem to be related to a DataSource. In my case there is no datasource since I am replacing the fields directly from Foxpro via OLE automation.
>
>2) Garret referred to a "MailMergeFields" collection. I could find only a MailMergeDataFields collection (which is related to the data source) and a MailMergeFieldNames collection. Help says "You cannot add names to the MailMergeFieldNames collection. When a field is added to a data source, the field name is automatically included in the MailMergeFieldNames collection." As I said, I don't have a data source.
>
>3) It occured to me that Bookmarks could be made visible by surrounding text which matched the name of the bookmark. For example:
>
>[OWNERS_CITY] where the bookmark name is OWNERS_CITY
>
>I thought it would be straigtforward to replace the dummy text with the actual text in FoxPro. I tried this (for example):
>
>goWord.activedocument.bookmarks("OWNERS_CITY").range.text ;
>= "CHARLOTTESVILLE"
>
>I discovered that this overlayed not only the original text ("OWNERS_CITY") but the bookmark itself. In general this replace operation seems to replace the text in the range plus the immediate character on either side of the range.
>
>I decided I could live with this by making a copy of the original document. I verifed that formating codes (bold, etc.) which surrounded the original bookmark would be applied to the replaced text even after the bookmark dissappeared.
>
>I tried this with a set of bookmarks that looked like this:
>
>[OWNERS_COMPANY]
>[OWNERS_ADDRLINE1]
>[OWNERS_ADDRLINE2]
>[OWNERS_CITY], [OWNERS_STATE] [OWNERS_POSTCODE]
>
>Unfortunately when I replaced [OWNERS_COMPANY] with "Rodes Software"+chr(13) I wound up with:
>
>[Rodes Software
>OWNERS_ADDRLINE1]
>[OWNERS_ADDRLINE2]
>[OWNERS_CITY], [OWNERS_STATE] [OWNERS_POSTCODE]
>
>The company name was now inside the boundaries of the ADDRLINE1 bookmark so that when it (OWNERS_ADDRLINE1) got replaced the company name dissappeared.
>
>This strangeness regarding the boudaries of the bookmarks can be experienced by trying to place a blank or CR immediately beyond a bookmark. Left and right boundaries act differently.
>
>So perhaps MailMergeFields are the way to go. But how to do it?
>
>4) The interaction between FoxPro and Word seems extraordinarily slow. I ran a loop to find and print six bookmarks in one document and it takes about three seconds to execute. Any suggestion?
>
>Peter Robinson

In regards to the bookmarks, if you call the select() method of the book mark and then use Selection.TypeText is will overwrite the book mark.

One of the gotchas with the Bookmark collection is that it is iterated in BookMark name order only. So if you remove the items while iterating, you will have to take into account that the count of the collection is diminished:

IOW:

FOR I = 1 to goWord.ActiveDocument.BookMarks.Count
goWord.ActiveDocument.BookMarks.Item(I).Select()
goWord.Selection.TypeText("Whatever") ENDFOR
Rick Hodder
MCP Visual Foxpro
C#, VB.NET Developer
Independent Consultant
www.RickHodder.com
MyBlog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform