PDA

View Full Version : VBA CODE ADDS BLANK LINE ON UNMERGE



stevembe
11-26-2013, 01:31 PM
Hoping somebody can help. I am using the following code that works perfectly less for one thing. The merged document has paragraph spaces that look like this:

Line of text

Line of text

However when run it extracts single documents but adds a blank space so it looks like this:

Line of text



Line of text

There is no character showing for this space and it is throwing all the pages out of sync. Has anybody please got any advice?


Sub BreakOnSection()
Application.Browser.Target = wdBrowseSection
For i = 1 To ((ActiveDocument.Sections.Count) - 1)
ActiveDocument.Bookmarks("\Section").Range.Copy
Documents.Add
Selection.Paste
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1

txtname = ActiveDocument.Range(Start:=ActiveDocument.Sentences(4).Start, End:=ActiveDocument.Sentences(4).End - 1).Text & ActiveDocument.Range(Start:=ActiveDocument.Sentences(5).Start, End:=ActiveDocument.Sentences(5).End - 1).Text
ChangeFileOpenDirectory "H:\Terms & Conditions\Test Unmerge"
'ActiveDocument.SaveAs FileName:="Terms & Conditions_" & Right(txtName, j - 1) & "_" & Left(txtName, Len(txtName) - j) & ".doc"
ActiveDocument.SaveAs FileName:=txtname & ".doc"
ActiveDocument.Close
Application.Browser.Next
Next i
'ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub

macropod
11-26-2013, 02:28 PM
It seems I was wasting my time here: http://www.vbaexpress.com/forum/showthread.php?48228-VBA-TO-UNMERGE-WORD-DOCUMENT-SAVE-WITH-UNIQUE-FILE-NAME-DEFINE-LOCATION

If you used the code I provided - and that you said works perfectly - this problem would not arise (assuming the mailmerge main document honoured the Style definitions in the template - you do do that, don't you?).

stevembe
11-26-2013, 02:53 PM
It did work perfectly once but it just now keeps giving errors. How do I copy your code without the code tags?

macropod
11-26-2013, 03:12 PM
It did work perfectly once but it just now keeps giving errors.

Well, code usually doesn't " work perfectly once" then just start producing errors. Furthermore, if you don't come back and say what errors you're getting, how is anyone supposed to help with that?

How do I copy your code without the code tags?
Umm, select, copy, paste... works for me.