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

Tip: Looking for answers? Try searching our database.

VBA Mailmerge

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 27 Jul 2004 16:53 GMT
I am pretty new to mail merges.  I am trying to write a macro to
extract a field value from a merge.  The only way I see doing this is
creating a mail merge macro.  If I write a mail merge macro how do I
display the contents of the field values on the document?  Also if I
want to record all of the values for a certain field say FieldA, how
do I extract the value to an array?  In other words which merge field
can I use to set to a array variable that will give me the field
value?  I know that I will probably have to somehow loop through the
field value to store each value for FieldA in the array.

Thanks

Mike
Peter Jamieson - 27 Jul 2004 23:21 GMT
In essence, when you execute a mailmerge from a macro, you lose control
until Word finishes merging, so you don't get to see the individual
values coming in from the data source. However, if you are working with
Word 2002/2003, you can use Word's mailmerge events to get (say)

Activedocument.MailMerge.DataSource.DataFields("the field name").Value

(or some such) as Word processes each record. You would have to
initialise and populate the array yourself.

You can also inspect these values in "normal" VBA (i.e. outside event
handlers) by moving the activerecord one at a time and inspecting the
records.

If you know what records the merge is supposed to be processing (e.g. if
 you do not allow user filtering, sorting, or data source selection),
you could consider using a more familiar way to get the data. For
example, for several types of data including Access, Excel and SQL
Server data, you could connect using ADO. You might need to ensure that
the Mailmerge Data Source was closed before doing so.

Peter Jamieson

> I am pretty new to mail merges.  I am trying to write a macro to
> extract a field value from a merge.  The only way I see doing this is
[quoted text clipped - 9 lines]
>
> Mike
 
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.