O
owen
I combined parts and modified the SplitMerge macros on site hosted by gmayor
(many thanks to graham and Doug Robbins); to name the split docs with unique
name from mergfield in doc and save to selected location. It works fine
except it creates an extra blank page with each letter, does any one know
what I need to change or add to keep the extra page from being created, or to
automatically delete it.
thanks,
owen
Here is the Macro as written:
Sub SplitMergeDocWithName()
' SplitMergeDoc Macro modified to save individual letters with
' information from data source. The filename data must be added to
' the top of the merge letter and must be unique.
Dim Default As String
Dim MyPath As String
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
Default = ""
Title = "Save To"
MyText = "Enter File Location"
MyPath = InputBox(MyText, Title, Default)
If MyPath = "" Then
End
End If
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 = MyPath & 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
(many thanks to graham and Doug Robbins); to name the split docs with unique
name from mergfield in doc and save to selected location. It works fine
except it creates an extra blank page with each letter, does any one know
what I need to change or add to keep the extra page from being created, or to
automatically delete it.
thanks,
owen
Here is the Macro as written:
Sub SplitMergeDocWithName()
' SplitMergeDoc Macro modified to save individual letters with
' information from data source. The filename data must be added to
' the top of the merge letter and must be unique.
Dim Default As String
Dim MyPath As String
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
Default = ""
Title = "Save To"
MyText = "Enter File Location"
MyPath = InputBox(MyText, Title, Default)
If MyPath = "" Then
End
End If
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 = MyPath & 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