View Single Post
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default macro for word mailmerge

In the simple case where you have a letter layout that uses one page and
always corresponds to a single record in the data source, you can use
something like

Sub batchmerge()
' number of records to process
' per batch
Const BatchSize As Long = 500
' a pathname for the output files
' We'll append the start record number
' (or you can merge to printer)
Const FileStem = "c:\a\batch_starting_"
Dim c As Long
Dim objDoc As Word.Document
c = 1
Set objDoc = ActiveDocument
With objDoc.MailMerge
.Destination = wdSendToNewDocument
While c = .DataSource.RecordCount
.DataSource.FirstRecord = c
.DataSource.LastRecord = c + BatchSize - 1
.Execute
ActiveDocument.SaveAs _
FileStem & CStr(c)
ActiveDocument.Close
c = c + BatchSize
Wend
End With
Set objDoc = Nothing
End Sub

If each letter always consumes (say) 5 records in the data source then
you could change
Const BatchSize = 500
to
Const BatchSize = 2500

However, if you have a more complicated letter where the number of
records each letter consumes (e.g. you are producing invoices) then it's
a different story because you do not actually know which record to start
with each time, and I don't believ it is particularly easy to find out.

Peter Jamieson

http://tips.pjmsn.me.uk

On 03/02/2010 15:38, Dirk wrote:
Hello
I want to seperate big mailmerge into 500 pages steps.
Can me somebody help to create this macro?
King regards in advanced.
Dirk