File Names for MailMerge Documents

K

Kristen

How do you save a new document generated from an existing MailMerge
Template/Document as the same name as the original document/template rather
than MS Word creating a new document with the merge info and calling it
"Letter1." For example, if my original document with the merge fields in it
is called Kristen when I select the merge function and the new document
opens, I want it to default to the name Kristen.doc when I use the
File-SaveAs command and then I will edit the file name before saving to be
Kristen013107(or something unique) before saving it so that it doesn't
overwrite the original Kristen.doc base merge template.

Likewise, is there a way after you save a file that is in a specified
directory after it has been merged, to have this file moved and/or copied to
another specified directory. Thanks in advance for any help!
 
K

Kristen

Thanks for the link Graham. The problem is that this macro also splits the
document into a new document for each record. Basically what I want is to
have the new document named via a data line in the main document like this
does, but not the other part with the splitting. Do you know where I can
find how to do this. It seems like it should be a fairly common request.
Thanks in advance!
 
K

Kristen

Hi Graham,

I actually don't want version numbers because the document needs to have the
result of a merged data field. Maybe it would be easier if I gave you an
example. The merge document has a Case ID# in it called Case_ID. The name
of the document is SoftwareNotice.doc. When the new document is created
after the merge, when I go to Save it, I want it to look at the merge field
Case_ID and name the document SoftwareNotice1234.doc, assuming that 1234 was
the Case_ID. Does this make sense? Thanks for all of your help and prompt
responses!
 
P

Peter Jamieson

You can use a macro like the following to perform the merge, but only if
your mail merge main document does not have any <<Next record>> fields and
similar stuff such as <<Next record if>>

Peter Jamieson

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 strEman As String
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. - you will need to change this -
strEman = StrReverse(objMerge.Name)
StrReverse(Mid(strEman, InStr(1, strEman & ".", ".") + 1))

strOutputDocumentName = _
"c:\mydoc\" & _
StrReverse(Mid(strEman, InStr(1, strEman & ".", ".") + 1)) & _
.DataSource.Datafields("CaseID").Value & ".doc"

.DataSource.FirstRecord = intSourceRecord
.DataSource.LastRecord = intSourceRecord
.Destination = wdSendToNewDocument
.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
 
G

Graham Mayor

Hmmm. If it's a single record merge then the original split merge add-in
solution should work. This names the file from a field (CaseID) in the
document?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Peter Jamieson

And you need to leave out this statement
ActiveDocument.Close

if you want to have the opportunity to change the nme before saving.

Peter Jamieson
 

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