Reply
 
Thread Tools Display Modes
  #1   Report Post  
Patrick De Wachter
 
Posts: n/a
Default Individual merge letters

Hello,

I've read the topic about Individual Merge Letters on the website of Graham
Mayor and it is very usefull for me, but I want to go somewhat further.

I would like to save the documents and include a mailmerge field as part of
the document name, instead of the date and a sequence number.

Do you have any suggetions how to pickup that data and use it in the DocName
in your VBA code.

Thanks for any input.

Patrick De Wachter

Belgium


  #2   Report Post  
Peter Jamieson
 
Posts: n/a
Default

As long as your merge generates one letter for each record in the data
source (i.e. you are not using fields such as NEXT or NEXTIF) there is
another way to generate one file per data source record:

Sub ProduceOneDocPerSourceRec()
' NB, needs better error management and doubtless other things a VBA expert
' will point out.
Dim intSourceRecord
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. Besides, it's clearer.

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

' 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

' while we are looking at the correct activerecord,
' create the document path name
' e.g. something like the following, but in this case
' each lastname must be unique (and must not contain
' characters that are not allowed in a file name)
strOutputDocumentName = _

"c:\mymergeletters\_" & _
..DataSource.Datafields("lastname").Value & _
" letter.doc"
..DataSource.FirstRecord = intSourceRecord
..DataSource.LastRecord = intSourceRecord
..Destination = wdSendToPrinter 'please check the constant name
..Execute

' The Activedocument is always the output document
' Add any parameters you need to these calls
ActiveDocument.SaveAs strOutputDocumentName
ActiveDocument.Close
intSourceRecord = intSourceRecord + 1
End If
Loop
End With
End Sub

Peter Jamieson

"Patrick De Wachter" wrote in message
...
Hello,

I've read the topic about Individual Merge Letters on the website of
Graham Mayor and it is very usefull for me, but I want to go somewhat
further.

I would like to save the documents and include a mailmerge field as part
of the document name, instead of the date and a sequence number.

Do you have any suggetions how to pickup that data and use it in the
DocName in your VBA code.

Thanks for any input.

Patrick De Wachter

Belgium




Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge Doc - Save letters when company site Changes Jan Mailmerge 3 April 7th 05 07:41 PM
Merge to printer as individual documents. nobag Mailmerge 2 March 28th 05 12:25 PM
save individual letters from a mail merge document Horta Mailmerge 6 March 25th 05 04:19 PM
Mail Merge is creating blank pages between form letters JW Mailmerge 1 January 25th 05 10:54 PM
Mail merge only creates first label when doing edit individual lab Scott H Mailmerge 1 January 19th 05 11:59 AM


All times are GMT +1. The time now is 10:54 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"