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 / Programming / February 2007

Tip: Looking for answers? Try searching our database.

changing code to also copy the header and footer 2 saved docs

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
S trainer - 06 Feb 2007 23:11 GMT
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
Jezebel - 06 Feb 2007 23:33 GMT
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")

> The following code works really well for splitting a merged document into
> separate documents and saving them as files; but the header and footer
[quoted text clipped - 24 lines]
>
> End Sub
S trainer - 07 Feb 2007 16:16 GMT
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.

> Simplest approach is to create a template that has the headers and footers
> you want, then create your new documents using that template --
[quoted text clipped - 29 lines]
> >
> > End Sub
Doug Robbins - Word MVP - 07 Feb 2007 18:22 GMT
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

Signature

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

> Jezebel,
>
[quoted text clipped - 49 lines]
>> >
>> > End Sub
S trainer - 07 Feb 2007 19:50 GMT
Thank you again Doug!

> 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
[quoted text clipped - 74 lines]
> >> >
> >> > End Sub
 
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.