MS Office Forum / Word / Mailmerge and Fax / April 2004
Merging, then saving letters as individual files?
|
|
Thread rating:  |
kpchop - 06 Feb 2004 16:47 GMT 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.
Debbie - 06 Feb 2004 17:40 GMT 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
>-----Original Message----- >I have a Word document that is linked to my Access [quoted text clipped - 11 lines] > >. Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS - 09 Feb 2004 08:21 GMT 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
 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
>I have a Word document that is linked to my Access > database through mailmerge. A separate letter is generated [quoted text clipped - 8 lines] > codes embedded in the master word document to separate > static word documents for each person. Hope - 15 Apr 2004 22:41 GMT 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.
Doug Robbins - Word MVP - 16 Apr 2004 03:32 GMT 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
 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
> 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. Hope - 16 Apr 2004 15:16 GMT 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" <anonymous@discussions.microsoft.com> wrote in message news:3C31A7E8-5912-4C5B-8E59-063C7FD6604C@microsoft.com... > 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.
Doug Robbins - Word MVP - 19 Apr 2004 10:23 GMT 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
 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
> 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 [quoted text clipped - 11 lines] > 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 [quoted text clipped - 41 lines] > expected, so I would appreciate any input! > > Thanks.
|
|
|