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 / August 2007

Tip: Looking for answers? Try searching our database.

mailmerging number of copies

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mar.s.i. - 29 Aug 2007 19:00 GMT
i have a word document and excel file as datasource for mailmerging.
what i want to accomplish is to mailmerge the document
printing (n times) based on datasource column per record.

is it possible?

thanks a lot
Peter Jamieson - 29 Aug 2007 19:16 GMT
As long as each printed document corresponds to a single record in your
Excel data source, you could try the following macro. I've tested this macro
without the "per copy" loop, but not with that extra loop, so there could be
errors in there:

Sub PrintXDocsPerSourceRec()
Dim intCopies As Integer
Dim intCopy As Integer
Dim intSourceRecord As Integer
Dim objMerge As Word.MailMerge
'Dim strOutputDocumentName As String
Dim TerminateMerge As Boolean

' Need to set up this object as the ActiveDocument changes when the
' merge is performed.

Set objMerge = ActiveDocument.MailMerge
With objMerge

 ' If no data source has been defined, do it here using OpenDataSource.
 ' But if it is already defined in the document, you should not need
 ' to define it here.

 ' .OpenDataSource _
 ' Name:="whatever"

 intSourceRecord = 1
 TerminateMerge = False

 Do Until TerminateMerge
   .DataSource.ActiveRecord = intSourceRecord

  ' Get the number of copies to print.
  ' Let's assume the number is in a column called "CopyCount"
  ' make sure you use exactly the same field name here
  ' - upper/lower case is significant

   intCopies = .DataSource.DataFields("CopyCount").Value

   ' if we have gone past the end (and possibly, if there are no records)
   ' then the Activerecord will not be what we have just tried to set it to

   If .DataSource.ActiveRecord <> intSourceRecord Then
     TerminateMerge = True
   ' the record exists
   Else
     For intCopy = 1 To intCopies
       .DataSource.FirstRecord = intSourceRecord
       .DataSource.LastRecord = intSourceRecord
       .Destination = wdSendToPrinter
       .Execute
     Next

     intSourceRecord = intSourceRecord + 1
   End If
 Loop
End With
End Sub

If you haven't used Word VBA Macros before, see

http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm

Signature

Peter Jamieson
http://tips.pjmsn.me.uk

>i have a word document and excel file as datasource for mailmerging.
> what i want to accomplish is to mailmerge the document
[quoted text clipped - 3 lines]
>
> thanks a lot

Rate this thread:






 
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.