Merging, then saving letters as individual files?

K

kpchop

I have a Word document that is linked to my Access
database through mailmerge. A separate letter is generated
for each person based on a query in Access as the source.
I would like to save a "static" copy of each letter as
individual files (not as one file in which the letters are
separated by section breaks). Could you advise me as to
how to save each letter "un-linked" from the source
database ? I would like to keep a copy of the letters.

I don't know if it is possible to easily convert the field
codes embedded in the master word document to separate
static word documents for each person.
 
D

Debbie

I actually did this on a very large scale. I had to code
it in VBA. If you would like to see some of the code just
let me know. I'd be happy to share with you. My project
was to create a letter which was merged with an access
database one record at a time and each letter was saved to
an individual word document with a unique field from the
database in the document name. I also had to convert the
documents to pdf's to be loaded to our website but you
won't have to do that part.

If you would like to send me an e-mail address I will send
you the code to get you started. It's a bit much to post
here.

Debbie
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

The following macro will do that:

' Macro created by Doug Robbins to save each letter created by a mailmerge
as a separate file.

Dim Letters As Integer, Counter As Integer
Letters = ActiveDocument.Sections.Count
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
DocName = "Myletter" & LTrim$(Str$(Counter))
ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
ActiveDocument.Sections(2).PageSetup.SectionStart = wdSectionContinuous
ActiveDocument.SaveAs FileName:=DocName, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveWindow.Close
Counter = Counter + 1
Wend

However, you will probably be better off to do it from Access using the
procedure provided by fellow MVP Albert Kallal at

http://www.attcanada.net/~kallal.msn/msaccess/msaccess.html




--
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
 
H

Hope

Your macro works great, however, I'm running into a couple of problems
1. If the original merged document contains 4 letters and the directory contains 4 records, the macro is only creating 3 new separate documents
2. Each new separate document has a section break-new page at the end of the letter so that I end up with 2 pages instead of one
Do you have any suggestions for solving this? I've gotten further than I expected, so I would appreciate any input
Thanks.
 
D

Doug Robbins - Word MVP

Not sure what macro you are referring to, but try:

Dim Letters As Integer, Counter As Integer, Source as Document, Target as
Document, Letter as Range
Set Source = ActiveDocument
Letters = Source.Sections.Count
For i = 1 to Letters
Set Letter = Source.Sections(i).Range
Letter.End=Letter.End-1
Set Target = Documents.Add
Target.Range=Letter
Target.SaveAs FileName:=â€Letter†& i, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
Target.Close
Next i


--
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
Hope said:
Your macro works great, however, I'm running into a couple of problems:
1. If the original merged document contains 4 letters and the
directory contains 4 records, the macro is only creating 3 new separate
documents.
2. Each new separate document has a section break-new page at the
end of the letter so that I end up with 2 pages instead of one.
Do you have any suggestions for solving this? I've gotten further than I
expected, so I would appreciate any input!
 
H

Hope

Sorry - didn't make myself clear enough. I created a directory that contains the file names that I want to save the separate documents as. Then I run the following macro. It is with this macro that I get the problem mentioned before.

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
DocumentName = "P:\hlock\winword\" & 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

----- Doug Robbins - Word MVP wrote: -----

Not sure what macro you are referring to, but try:

Dim Letters As Integer, Counter As Integer, Source as Document, Target as
Document, Letter as Range
Set Source = ActiveDocument
Letters = Source.Sections.Count
For i = 1 to Letters
Set Letter = Source.Sections(i).Range
Letter.End=Letter.End-1
Set Target = Documents.Add
Target.Range=Letter
Target.SaveAs FileName:=â€Letter†& i, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
Target.Close
Next i


--
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
Hope said:
Your macro works great, however, I'm running into a couple of problems:
1. If the original merged document contains 4 letters and the
directory contains 4 records, the macro is only creating 3 new separate
documents.
2. Each new separate document has a section break-new page at the
end of the letter so that I end up with 2 pages instead of one.
Do you have any suggestions for solving this? I've gotten further than I
expected, so I would appreciate any input!
 
D

Doug Robbins - Word MVP

Make use of

Set Letter = Source.Sections(i).Range
Letter.End=Letter.End-1
Set Target = Documents.Add
Target.Range=Letter

in place of

Source.Sections.First.Range.Cut
Documents.Add
Selection.Paste


--
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
Hope said:
Sorry - didn't make myself clear enough. I created a directory that
contains the file names that I want to save the separate documents as. Then
I run the following macro. It is with this macro that I get the problem
mentioned before.
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
DocumentName = "P:\hlock\winword\" & 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
 

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