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 / February 2004

Tip: Looking for answers? Try searching our database.

How to get the Names of the MailMerge Fields in the document(word 2003)?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ram - 16 Feb 2004 23:58 GMT
I am automating MailMerge and do not want to process the document if
the user has not supplied all the data needed to perform MailMerge.
This is the only way I can think of for suppressing the Message boxes
since the C# application runs as a service. Is there a way we can find
the names of the MailMerge fields after loading the document?

Can anyone help?

Thanks,
Ram
Peter Jamieson - 17 Feb 2004 06:15 GMT
You can get the names of the fields in the data source by looking at the
ActiveDocument.MailMerge.DataSource.DataFields collection.

For the names of fields used in the document, you could try something like
the following (after converting to C# of course). It inspects /all/ field
types. I wouldn't guarantee that it will find them all (e.g. it may not get
everything in the graphics layer) but it's the nearest I've ever got.

Sub IterateMergeFields()
Dim r As Range
Dim f As Field
Dim s As Shape
For Each r In ActiveDocument.StoryRanges
 If r.StoryType <> wdTextFrameStory Then
   For Each f In r.Fields
     If f.Type = wdFieldMergeField Then
       ' do whatever you need
     End If
   Next
 End If
Next
For Each s In ActiveDocument.Shapes
 If s.Type = msoTextBox Then
   For Each f In s.TextFrame.TextRange.Fields
     If f.Type = wdFieldMergeField Then
       ' do whatever you need
     End If
   Next
 End If
Next
End Sub

I would be interested to know if you have found a reliable way to deal with
mail merge main documents that cannot find their data source - typically
there is nothing you can do to prevent Word displaying a dialog box when
that occurs.
--
Peter Jamieson - Word MVP
Word MVP web site http://word.mvps.org/

> I am automating MailMerge and do not want to process the document if
> the user has not supplied all the data needed to perform MailMerge.
[quoted text clipped - 6 lines]
> Thanks,
> Ram
 
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.