![]() |
|
|
|
#1
|
|||
|
|||
|
Hello all,
I am trying to use a macro that splits a mail merge into multiple word files. Below is the code that I am using. This macro works great except that it ignores the spacing of my mail merged word doc. It turns: Line1 Line2 line3 into Line1 Line2 Line3 How can I preserve the original spacing into the new docs? Code:
Sub Spliter()
'Used to set criteria for moving through the document by section.
Application.Browser.Target = wdBrowseSection
'A mailmerge document ends with a section break next page.
'Subtracting one from the section count stop error message.
For i = 1 To ((ActiveDocument.Sections.Count) - 1)
'Select and copy the section text to the clipboard
ActiveDocument.Bookmarks("\Section").Range.Copy
'Create a new document to paste text from clipboard.
Documents.Add
Selection.Paste
'Removes the break that is copied at the end of the section, if any.
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ChangeFileOpenDirectory "C:\"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="Testing_" & DocNum & ".doc"
ActiveDocument.Close
'Move the selection to the next section in the document
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
HTML Code:
http://word.tips.net/T001538_Merging_to_Individual_Files.html Selection.Paste with Selection.PasteAndFormat (wdFormatOriginalFormatting) The last thing that is giving me a head on this issue is that the header and footer are not keeping their formats. Any ideas? Last edited by lonesoac0; 10-15-2015 at 06:35 AM. Reason: Fixed one issue and another came up. |
|
#2
|
||||
|
||||
|
See:
• Send Mailmerge Output to Individual Files; and • Split Merged Output to Separate Documents, in the Mailmerge Tips and Tricks 'Sticky' thread in the mailmerge forum: https://www.msofficeforums.com/mail-...ps-tricks.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
| Tags |
| spacing, vba code |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Adjusting Header Space and Counter-adjusting another space setting to ensure identical page content
|
cgp1689 | Word | 3 | 10-14-2015 07:34 AM |
adjusting print
|
aubbieed | Word | 5 | 08-18-2015 08:55 AM |
| Adjusting column widths | norwood | Word VBA | 0 | 09-24-2013 06:53 AM |
| Adjusting All Durations by 10% | skoz55 | Project | 1 | 01-13-2012 08:26 AM |
| Adjusting Tabs | erselking | Word | 1 | 10-23-2008 02:57 PM |