Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / June 2006

Tip: Looking for answers? Try searching our database.

retrieving merge field names

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Francisc Molnar - 06 Jun 2006 17:19 GMT
Hi all
I am programmatically(C#, using the PIA) changing the datasource for a word
document, wich contains some merge fields.
In order to avoid the prompt wich signals that certain fields have no
correspondent in the new datasource, I would like to obtain the merge field
names and check if the datasource has a corresponding column for each one of
them (if not - I will not call MailMerge.Execute()).
I cannot find a reasonable way to retrieve the merge field name (I cannot
obtain it like this: <<field>> -> field ... it's not always the same.)  
Should I parse the MailMergeField.Code.Text ? ... I think it's not a very
good idea...
Thanks
Doug Robbins - Word MVP - 06 Jun 2006 19:36 GMT
The following VBA code will give you the names of the mergefields in the
activedocument:

Dim af As Field
For Each af In ActiveDocument.Fields
   If af.Type = wdFieldMergeField Then
       MsgBox Mid(af.Code, InStr(af.Code, Chr(34)))
   End If
Next af

You may need to strip off the quote marks for your purposes.

Can't help you with C#

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi all
> I am programmatically(C#, using the PIA) changing the datasource for a
[quoted text clipped - 11 lines]
> good idea...
> Thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.