Saving merged documents as seperate documents

M

Marie T

The merge produces multiple documents. How can I save the
merged documents as seperate documents. Each document name
has to be assigned by the user.

Thanks for any suggestions.
 
P

Peter Jamieson

In simple cases you could use VBA to perform one merge for each data source
record in turn, and get the target document name from the user. e.g.

{ IF { MERGEFIELD myzip } > 99999
"{ MERGEFIELD myzip \#"00000'-'0000" }"
"{ MERGEFIELD myzip \#"00000" }-0000" }

if you always want a 5-4 format, or

{ IF { MERGEFIELD myzip } > 99999
"{ MERGEFIELD myzip \#"00000'-'0000" }"
"{ MERGEFIELD myzip \#"00000" }" }

otherwise.
 
P

Peter Jamieson

You need a VBA macro to do this - if the merge is simple and only processes
one data source record per output document, you could use VBA to perfoorm
one merge for each record in the data source, and ask the user for a
path/file name so you can save each document. Or you could do the entire
merge to an output document and use a macro to split the file using e.g.
Section breaks to determine where to make the split. Again, you would prompt
the user for the file names for each file.

An example of code for the former approach would be:

Sub ProduceOneDocPerSourceRec()
'

' NB, needs bettor 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

.DataSource.FirstRecord = intSourceRecord
.DataSource.LastRecord = intSourceRecord
.Destination = wdSendToNewDocument
.Execute

' Get a path name from the user (you would need more than this
' in practice in order to validate the path,
' but I've inserted this as an example
strOutputDocumentName = InputBox("Input the full path name of the
document", _
"Output document", "", 1000, 1000)
' 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

If you need the other approach to splitting the file, there is code at
Graham Mayor's site for a couple of examples which you could adapt in a
similar way:
http://www.gmayor.dsl.pipex.com/individual_merge_letters.htm
..
 
P

Peter Jamieson

Sorry for that bizarre reply, which was in response to a completely
different question. Please see my other response.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top