Break up Mail Merge into separate documents

C

Craig

Hi,
A mail merge produces one large document. I would like to
know if there is a way to chop up this document into
separate documents.

For example, if I run a mail merge for a personalized
letter to 30 people, now I have one document -- but I want
to have 30 separate letters, each of which I would like to
email to the correct recipient.

Any ideas? Ideally, I would like the 30 letters to save
with file names that allow me to easily identify which
letter goes with which email. for instance, the file name
could be based upon 1 or more of the merge codes in the
letter.
thanks,
Craig
 
D

Doug Robbins - Word MVP

Here's a method that I have used that involves creating a separate
catalog type mailmerge maindocument which creates a word document containing
a table in each row of which would be your data from the database that you
want to use as the filename.

You first execute that mailmerge, then save that file and close it. Then
execute the mailmerge that you want to create the separate files from and
with the
result of that on the screen, run a macro containing the following code
and when the File open dialog appears, select the file containing the table
created by the first mailmerge

Dim Source As Document, oblist As Document, DocName As Range, DocumentName
As String
Set Source = ActiveDocument
With Dialogs(wdDialogFileOpen)
.Show
End With
Set oblist = ActiveDocument
Counter = 1
While Counter < oblist.Tables(1).Rows.Count
Set DocName = oblist.Tables(1).Cell(Counter, 1).Range
DocName.End = DocName.End - 1

'Change the path in the following command to suit where you want to save
the documents.
DocumentName = "I:\WorkArea\Documentum\" & DocName.Text
Source.Sections.First.Range.Cut
Documents.Add
Selection.Paste
ActiveDocument.SaveAs filename:=DocumentName, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveWindow.Close
Counter = Counter + 1
Wend


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
G

Guest

Hi Doug,
Thank you for your reply. I am new to macros. I created
the catalog and created the 2nd mail merge, but when I try
to execute the macro, I receive a VBA error:

Compile Error: Syntax Error

Any idea what I may be doing wrong. Here is the text of
the macro I made from your previous message. Thank you
again so much for the help.
Craig

Sub Splitter()
'
' Splitter Macro
' Macro created 5/4/2004 by Craig Friedman
'
Dim Source As Document, oblist As Document, DocName As
Range, DocumentName
As String
Set Source = ActiveDocument
With Dialogs(wdDialogFileOpen)
.Show
End With
Set oblist = ActiveDocument
Counter = 1
While Counter < oblist.Tables(1).Rows.Count
Set DocName = oblist.Tables(1).Cell(Counter, 1).Range
DocName.End = DocName.End - 1

'Change the path in the following command to suit
where you want to save
the documents.
DocumentName = "I:\WorkArea\Documentum\" & DocName.Text
Source.Sections.First.Range.Cut
Documents.Add
Selection.Paste
ActiveDocument.SaveAs filename:=DocumentName,
FileFormat:= _
wdFormatDocument, LockComments:=False,
Password:="",
AddToRecentFiles:= _
True, WritePassword:="",
ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False,
SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveWindow.Close
Counter = Counter + 1
Wend

End Sub
 
D

Doug Robbins - Word MVP

What line of code is highlighted when the error occurs. Are there any lines
in red which would indicate a missing line break.

Also undoubtably you will need to change the path to the folder in which the
documents are being saved.

See the article "What do I do with macros sent to me by other newsgroup
readers to help me out?" at:

http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
G

Guest

Hi Doug,
Sorry, I meant to include the highlighted line. It is the
second line: "As String"

I know that I need to change the path, but the macro
doesn't get to that point.

The below text is in red. Any help you might provide would
be appreciated. Thank you for sending the link bout sent
macros -- I will read that in the meantime.
Craig

ActiveDocument.SaveAs filename:=DocumentName,
FileFormat:= _
wdFormatDocument, LockComments:=False,
Password:="",
AddToRecentFiles:= _
True, WritePassword:="",
ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False,
SaveFormsData:=False, _
SaveAsAOCELetter:=False
 
D

Doug Robbins - Word MVP

That command is in red because the email program has inserted line breaks
without the visual basic _ line break character.

Place the cusor at the beginning of each line following a line that
terminates with a _ use backspace to remove the newline inserted by the
email program.

Likewise, all of this was originally one line of code

Dim Source As Document, oblist As Document, DocName As
Range, DocumentName
As String
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
G

Guest

Thank you, Doug. Now I have 2 remaining questions, and if
you could answer these I would be very appeciative.

1. Your macro runs great, except that no document is saved
for the last record in the catalog document. The last
section of the mail merge remains open on screen, and no
doc is saved. Any idea why?
2. I'd like to modify the macro so that the doc name is in
the second column of the catalog. How might I do this? In
the first column of the catalog, I have the email of the
person to whom the document should be sent, and in the
second column I have the document name. For example:

(e-mail address removed) c:\mail merge docs\bob123.doc

Any and all help appreciated.
Thank you,
Craig
 
G

Guest

In case it is relevant to my last 2 questions, I did
change one line of your macro. I changed the line:

DocumentName = "I:\WorkArea\Documentum\" & DocName.Text

To:

DocumentName = DocName.Text

I did this because I have the full path, file name and
extension in my catalog already. For example: C:\mail
merge docs\bob123.doc. I didn't think this would make a
difference explaining why the last doc does not save, but
thought I'd let you know, just in case.
Thank you,
Craig
 
D

Doug Robbins - Word MVP

Change

While Counter < oblist.Tables(1).Rows.Count

to

While Counter <= oblist.Tables(1).Rows.Count

if the docname is in the second column, then use

Set DocName = oblist.Tables(1).Cell(Counter, 2).Range

in place of

Set DocName = oblist.Tables(1).Cell(Counter, 1).Range

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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