View Single Post
  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
 
Posts: n/a
Default MS Word - Creat a new document for each record

The macro assumes that each document is in a single section, not a single
page.

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

"Teeroi" wrote in message
oups.com...
Thanks - the last macro on the page does most of what I was looking
for. The only problem I'm running into is this - the macro apparently
assumes the documents is a single page, where as mine is actually 3
pages. Thus, after it reads the top line and creates the file, it
errors trying to read the top line of the next page, which is actually
part of the first document. Is there a way to programmatically assign
the number of pages per document? I've copied the macro code below.
Thanks again for you help in advance.

Sub SplitMergeLetter()
' splitter Macro modified to save individual letters with

' information from data source. The filename data must be added to

' the top of the merge letter - see web article.


Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
With Selection

.HomeKey Unit:=wdStory
.EndKey Unit:=wdLine, Extend:=wdExtend
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

End With
sName = Selection
Docname = "F:\Datapath\" & sName & ".doc"
ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.HomeKey Unit:=wdStory
.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
.Delete
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend

End Sub