
Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Thanks for the link Graham. The problem is that this macro also
> splits the document into a new document for each record. Basically
[quoted text clipped - 31 lines]
>>> moved and/or copied to another specified directory. Thanks in
>>> advance for any help!
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!
> This sounds like you want to create 'versions' - see another macro on my web
> site at http://www.gmayor.com/save_numbered_versions.htm which could be
[quoted text clipped - 35 lines]
> >>> moved and/or copied to another specified directory. Thanks in
> >>> advance for any help!
Peter Jamieson - 01 Feb 2007 19:39 GMT
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
> Hi Graham,
>
[quoted text clipped - 51 lines]
>> >>> moved and/or copied to another specified directory. Thanks in
>> >>> advance for any help!
Peter Jamieson - 02 Feb 2007 08:20 GMT
And you need to leave out this statement
> ActiveDocument.Close
if you want to have the opportunity to change the nme before saving.
> 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
[quoted text clipped - 125 lines]
>>> >>> moved and/or copied to another specified directory. Thanks in
>>> >>> advance for any help!
Graham Mayor - 02 Feb 2007 07:17 GMT
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?

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Hi Graham,
>
[quoted text clipped - 55 lines]
>>>>> moved and/or copied to another specified directory. Thanks in
>>>>> advance for any help!