Sub Splitter()
'------------------------------------------------------------------------------------------------------------------
' splitter Macro
' Macro created by Doug Robbins to save each letter created by a mailmerge as a separate file.
' 'Mutulated' by Octafish to add first paragraph to DocName.
'------------------------------------------------------------------------------------------------------------------
Dim Letters As Integer, Counter As Integer
Dim DocName As String, sRange As String
Dim Pad As String, sNullen As String
Dim aRange As Range
DocName = "Brief "
Pad = "H:\Temp\Word\"
Letters = ActiveDocument.Sections.Count
For Counter = 1 To Len(Letters)
sNullen = sNullen & "0"
Next Counter
sNullen = sNullen & "0"
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
'-----------------------------------------------------------------------------
'Naam samenstellen op basis van nummering
'-----------------------------------------------------------------------------
DocName = Right(sNullen & LTrim$(Str$(Counter)), Len(Letters) + 1) & "_"
'-----------------------------------------------------------------------------
ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
'-----------------------------------------------------------------------------
'Naam samenstellen uit 1e alinea van tekst
'-----------------------------------------------------------------------------
Set aRange = ActiveDocument.Paragraphs(1).Range
DocName = DocName & aRange.Text
If Right(DocName, 1) = Chr(13) Or Right(DocName, 1) = Chr(10) Then
DocName = Left(DocName, Len(DocName) - 1)
End If
'-----------------------------------------------------------------------------
'Bestand opslaan
'-----------------------------------------------------------------------------
ActiveDocument.Sections(2).PageSetup.SectionStart = wdSectionContinuous
ActiveDocument.SaveAs FileName:=Pad & DocName & ".doc", _
FileFormat:=wdFormatDocument, LockComments:=False, _
Password:="", AddToRecentFiles:=True, WritePassword:="", _
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, _
SaveFormsData:=False, SaveAsAOCELetter:=False
ActiveWindow.Close
Counter = Counter + 1
'-----------------------------------------------------------------------------
Wend
End Sub