Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2015, 06:12 AM
lonesoac0 lonesoac0 is offline Adjusting a macro Windows 7 64bit Adjusting a macro Office 2013
Novice
Adjusting a macro
 
Join Date: Oct 2015
Posts: 10
lonesoac0 is on a distinguished road
Default Adjusting a macro

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
Here is the site I got the original code from:
HTML Code:
http://word.tips.net/T001538_Merging_to_Individual_Files.html
An update on this issue. I figured out formatting issue for the text. I replaced:

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.
Reply With Quote
  #2  
Old 10-15-2015, 04:40 PM
macropod's Avatar
macropod macropod is online now Adjusting a macro Windows 7 64bit Adjusting a macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

Tags
spacing, vba code



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adjusting a macro Adjusting Header Space and Counter-adjusting another space setting to ensure identical page content cgp1689 Word 3 10-14-2015 07:34 AM
Adjusting a macro 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

Other Forums: Access Forums

All times are GMT -7. The time now is 07:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft