Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / May 2004

Tip: Looking for answers? Try searching our database.

Break up Mail Merge into separate documents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Craig - 22 Apr 2004 22:50 GMT
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
Doug Robbins - Word MVP - 23 Apr 2004 05:24 GMT
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

Signature

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

> Hi,
> A mail merge produces one large document. I would like to
[quoted text clipped - 13 lines]
> thanks,
> Craig
- 04 May 2004 22:38 GMT
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

>-----Original Message-----
>Here's a method that I have used that involves creating a separate
[quoted text clipped - 57 lines]
>
>.
Doug Robbins - Word MVP - 05 May 2004 03:14 GMT
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

Signature

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

> Hi Doug,
> Thank you for your reply. I am new to macros. I created
[quoted text clipped - 140 lines]
> >
> >.
- 05 May 2004 14:57 GMT
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

>-----Original Message-----
>What line of code is highlighted when the error occurs.  Are there any lines
[quoted text clipped - 154 lines]
>
>.
Doug Robbins - Word MVP - 06 May 2004 13:49 GMT
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
Signature

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

> Hi Doug,
> Sorry, I meant to include the highlighted line. It is the
[quoted text clipped - 203 lines]
> >
> >.
- 14 May 2004 17:49 GMT
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:

bob@hotmail.org   c:\mail merge docs\bob123.doc

Any and all help appreciated.
Thank you,
Craig

>-----Original Message-----
>That command is in red because the email program has inserted line breaks
[quoted text clipped - 218 lines]
>
>.
Doug Robbins - Word MVP - 15 May 2004 06:24 GMT
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

Signature

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

> Thank you, Doug. Now I have 2 remaining questions, and if
> you could answer these I would be very appeciative.
[quoted text clipped - 266 lines]
> >
> >.
- 14 May 2004 17:55 GMT
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

>-----Original Message-----
>That command is in red because the email program has inserted line breaks
[quoted text clipped - 218 lines]
>
>.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.