The following code works really well for splitting a merged document into
separate documents and saving them as files; but the header and footer
information from the original merged document is missing in the individual
documents. Is it possible to have the footer and header from the original
merge document appear in the individual documents?


Sub MailMergeLetterSplitter()
'
' MailMergeLetterSplitter Macro
' Macro created 1/24/2007 by solsenb
'
' splitter Macro

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

Dim i As Long, Source As Document, Target As Document, Letter As Range
Set Source = ActiveDocument
For i = 1 To Source.Sections.Count
Set Letter = Source.Sections(i).Range
Letter.End = Letter.End - 1
Set Target = Documents.Add
Target.Range = Letter
Target.SaveAs FileName:="Letter" & i
Target.Close
Next i

End Sub

Re: changing code to also copy the header and footer 2 saved docs by Jezebel

Jezebel
Tue Feb 06 17:33:28 CST 2007

Simplest approach is to create a template that has the headers and footers
you want, then create your new documents using that template --

Set Target = Documents.Add(Template:="myTemplate.dot")



"S trainer" <Strainer@discussions.microsoft.com> wrote in message
news:ECC4C822-BE2F-45C1-A9A1-A9644EA3845D@microsoft.com...
> The following code works really well for splitting a merged document into
> separate documents and saving them as files; but the header and footer
> information from the original merged document is missing in the individual
> documents. Is it possible to have the footer and header from the original
> merge document appear in the individual documents?
>
>
> Sub MailMergeLetterSplitter()
> '
> ' MailMergeLetterSplitter Macro
> ' Macro created 1/24/2007 by solsenb
> '
> ' splitter Macro
>
> ' Macro created by Doug Robbins to save each letter created by a mailmerge
> as a separate file.
>
> Dim i As Long, Source As Document, Target As Document, Letter As Range
> Set Source = ActiveDocument
> For i = 1 To Source.Sections.Count
> Set Letter = Source.Sections(i).Range
> Letter.End = Letter.End - 1
> Set Target = Documents.Add
> Target.Range = Letter
> Target.SaveAs FileName:="Letter" & i
> Target.Close
> Next i
>
> End Sub
>



Re: changing code to also copy the header and footer 2 saved docs by Strainer

Strainer
Wed Feb 07 10:16:00 CST 2007

Jezebel,

Thank you for answering so quickly.

The main merge document all ready has the header and footer needed, the
merged document (all of the letters in one document) has the header and
footer needed, but through the processing of the code below, which separates
each of the letters from the merged document and saves them each to a
separate file, the header and footer are missing in the separated files.

Any ideas to keep the header and footer in the separated letters?

Thanks.

"Jezebel" wrote:

> Simplest approach is to create a template that has the headers and footers
> you want, then create your new documents using that template --
>
> Set Target = Documents.Add(Template:="myTemplate.dot")
>
>
>
> "S trainer" <Strainer@discussions.microsoft.com> wrote in message
> news:ECC4C822-BE2F-45C1-A9A1-A9644EA3845D@microsoft.com...
> > The following code works really well for splitting a merged document into
> > separate documents and saving them as files; but the header and footer
> > information from the original merged document is missing in the individual
> > documents. Is it possible to have the footer and header from the original
> > merge document appear in the individual documents?
> >
> >
> > Sub MailMergeLetterSplitter()
> > '
> > ' MailMergeLetterSplitter Macro
> > ' Macro created 1/24/2007 by solsenb
> > '
> > ' splitter Macro
> >
> > ' Macro created by Doug Robbins to save each letter created by a mailmerge
> > as a separate file.
> >
> > Dim i As Long, Source As Document, Target As Document, Letter As Range
> > Set Source = ActiveDocument
> > For i = 1 To Source.Sections.Count
> > Set Letter = Source.Sections(i).Range
> > Letter.End = Letter.End - 1
> > Set Target = Documents.Add
> > Target.Range = Letter
> > Target.SaveAs FileName:="Letter" & i
> > Target.Close
> > Next i
> >
> > End Sub
> >
>
>
>

Re: changing code to also copy the header and footer 2 saved docs by Doug

Doug
Wed Feb 07 12:22:20 CST 2007

The Header/Footer information is contained in the Section Break that appears
at the end of each merged letter. As for all merged letters, other than the
last, the Section Break is a Next Page Section Break, the following line of
code:

Letter.End = Letter.End - 1

was used to delete that Section Break so that there would not be an empty
page at the end of each separated letter.
By deleting the Section Break, the header and footer are being deleted. The
following modified code, converts each Section Break to a Continuous Section
Break, that will eliminate the empty page (unless the previous page is full
to the gills), rather than delete the Section Break.

Dim i As Long, Source As Document, Target As Document, Letter As Range
Set Source = ActiveDocument
For i = 1 To Source.Sections.Count
Set Letter = Source.Sections(i).Range
Set Target = Documents.Add
Target.Range = Letter
Target.Sections(Last).PageSetup.SectionStart = wdSectionContinuous
Target.SaveAs FileName:="Letter" & i
Target.Close
Next i


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"S trainer" <Strainer@discussions.microsoft.com> wrote in message
news:EBD711EB-C286-49EF-93D3-014A42B965E6@microsoft.com...
> Jezebel,
>
> Thank you for answering so quickly.
>
> The main merge document all ready has the header and footer needed, the
> merged document (all of the letters in one document) has the header and
> footer needed, but through the processing of the code below, which
> separates
> each of the letters from the merged document and saves them each to a
> separate file, the header and footer are missing in the separated files.
>
> Any ideas to keep the header and footer in the separated letters?
>
> Thanks.
>
> "Jezebel" wrote:
>
>> Simplest approach is to create a template that has the headers and
>> footers
>> you want, then create your new documents using that template --
>>
>> Set Target = Documents.Add(Template:="myTemplate.dot")
>>
>>
>>
>> "S trainer" <Strainer@discussions.microsoft.com> wrote in message
>> news:ECC4C822-BE2F-45C1-A9A1-A9644EA3845D@microsoft.com...
>> > The following code works really well for splitting a merged document
>> > into
>> > separate documents and saving them as files; but the header and footer
>> > information from the original merged document is missing in the
>> > individual
>> > documents. Is it possible to have the footer and header from the
>> > original
>> > merge document appear in the individual documents?
>> >
>> >
>> > Sub MailMergeLetterSplitter()
>> > '
>> > ' MailMergeLetterSplitter Macro
>> > ' Macro created 1/24/2007 by solsenb
>> > '
>> > ' splitter Macro
>> >
>> > ' Macro created by Doug Robbins to save each letter created by a
>> > mailmerge
>> > as a separate file.
>> >
>> > Dim i As Long, Source As Document, Target As Document, Letter As Range
>> > Set Source = ActiveDocument
>> > For i = 1 To Source.Sections.Count
>> > Set Letter = Source.Sections(i).Range
>> > Letter.End = Letter.End - 1
>> > Set Target = Documents.Add
>> > Target.Range = Letter
>> > Target.SaveAs FileName:="Letter" & i
>> > Target.Close
>> > Next i
>> >
>> > End Sub
>> >
>>
>>
>>



Re: changing code to also copy the header and footer 2 saved docs by Strainer

Strainer
Wed Feb 07 13:50:02 CST 2007

Thank you again Doug!

"Doug Robbins - Word MVP" wrote:

> The Header/Footer information is contained in the Section Break that appears
> at the end of each merged letter. As for all merged letters, other than the
> last, the Section Break is a Next Page Section Break, the following line of
> code:
>
> Letter.End = Letter.End - 1
>
> was used to delete that Section Break so that there would not be an empty
> page at the end of each separated letter.
> By deleting the Section Break, the header and footer are being deleted. The
> following modified code, converts each Section Break to a Continuous Section
> Break, that will eliminate the empty page (unless the previous page is full
> to the gills), rather than delete the Section Break.
>
> Dim i As Long, Source As Document, Target As Document, Letter As Range
> Set Source = ActiveDocument
> For i = 1 To Source.Sections.Count
> Set Letter = Source.Sections(i).Range
> Set Target = Documents.Add
> Target.Range = Letter
> Target.Sections(Last).PageSetup.SectionStart = wdSectionContinuous
> Target.SaveAs FileName:="Letter" & i
> Target.Close
> Next i
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "S trainer" <Strainer@discussions.microsoft.com> wrote in message
> news:EBD711EB-C286-49EF-93D3-014A42B965E6@microsoft.com...
> > Jezebel,
> >
> > Thank you for answering so quickly.
> >
> > The main merge document all ready has the header and footer needed, the
> > merged document (all of the letters in one document) has the header and
> > footer needed, but through the processing of the code below, which
> > separates
> > each of the letters from the merged document and saves them each to a
> > separate file, the header and footer are missing in the separated files.
> >
> > Any ideas to keep the header and footer in the separated letters?
> >
> > Thanks.
> >
> > "Jezebel" wrote:
> >
> >> Simplest approach is to create a template that has the headers and
> >> footers
> >> you want, then create your new documents using that template --
> >>
> >> Set Target = Documents.Add(Template:="myTemplate.dot")
> >>
> >>
> >>
> >> "S trainer" <Strainer@discussions.microsoft.com> wrote in message
> >> news:ECC4C822-BE2F-45C1-A9A1-A9644EA3845D@microsoft.com...
> >> > The following code works really well for splitting a merged document
> >> > into
> >> > separate documents and saving them as files; but the header and footer
> >> > information from the original merged document is missing in the
> >> > individual
> >> > documents. Is it possible to have the footer and header from the
> >> > original
> >> > merge document appear in the individual documents?
> >> >
> >> >
> >> > Sub MailMergeLetterSplitter()
> >> > '
> >> > ' MailMergeLetterSplitter Macro
> >> > ' Macro created 1/24/2007 by solsenb
> >> > '
> >> > ' splitter Macro
> >> >
> >> > ' Macro created by Doug Robbins to save each letter created by a
> >> > mailmerge
> >> > as a separate file.
> >> >
> >> > Dim i As Long, Source As Document, Target As Document, Letter As Range
> >> > Set Source = ActiveDocument
> >> > For i = 1 To Source.Sections.Count
> >> > Set Letter = Source.Sections(i).Range
> >> > Letter.End = Letter.End - 1
> >> > Set Target = Documents.Add
> >> > Target.Range = Letter
> >> > Target.SaveAs FileName:="Letter" & i
> >> > Target.Close
> >> > Next i
> >> >
> >> > End Sub
> >> >
> >>
> >>
> >>
>
>
>