Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spilt Word Mail merge and assigns a merge field name as the filename but the macro adds extra lines

Status
Not open for further replies.

shaleen7

MIS
Jun 23, 2002
188
0
0
US
Hi All,

I'm not an expert on VBA so I found this could this code online to split a word mail merge document & assign the filename based on a merge field name. It works perfectly except it adds extra lines of space in the merged documents. A 2 page document is now 5 pages because of the extra lines of space. Why is this happening? What change needs to happen to the code? Many Thanks!


Sub SplitMergeLetter()

Dim sName As String
Dim docName As String
Dim Letters As String
Dim Counter As Long
Dim oDoc As Document
Dim oNewDoc As Document
Set oDoc = ActiveDocument
oDoc.Save
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 = "C:\Letter4\" & sName & ".doc"
oDoc.Sections.First.Range.Cut
Set oNewDoc = Documents.Add
'Documents are based on the Normal template
'To use an alternative template follow the link.
With Selection
.Paste
.HomeKey Unit:=wdStory
.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
.Delete
End With
oNewDoc.SaveAs FileName:=docName, _
FileFormat:=wdFormatDocument, _
AddToRecentFiles:=False
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
oDoc.Close wdDoNotSaveChanges
End Sub
 
Hi,

Just out of curiosity, if you were to manually step through the merge in you document, turning on the Preview Results control that fills each Mail Metge Field with actual values, what happens to your 2 page document?
 
It looks like after every return the macro adds a single space line.
 
Is there an actual paragraph mark added or is the line spacing now set to >1.0?
 
I suggested that you do the merge MANUALLY, without the macro, in order to determine if this is occurring without the macro!

Also make your paragraph marks visible using the File > Paragraph > Show/Hide icon
 
I have no idea what that code is doing, but it isn't doing what you say. Rather than trying to mess with it, throw it away and get some code that works.

Graham Mayor, Word MVP, has an Addin that will do exactly what you want - see

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
For that matter take a look at this FAQ:

How to MAIL MERGE and PRINT each Recipient Separately
faq68-6655

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top