Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Dec 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Keep Source Format (MS Word 2002)

    I'm working with a merged document and am able to split and save the merged document to individual documents; however, I need the individual documents to keep the source formatting.

    Here is the macro:

    <pre>Sub SplitMergeLetter()
    '
    ' SplitMergeLetter Macro
    ' Macro created September 29, 2005 by Anonimo
    ' splitter Macro modified to save individual letters with
    ' information from data source. The filename data must be added to
    ' the top of the merge letter - see web article.


    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 = "D:Temp" & sName & ".doc"
    ActiveDocument.Sections.First.Range.Cut
    Documents.Add
    With Selection
    .PasteAndFormat (wdPasteDefault)
    .HomeKey Unit:=wdStory
    .MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
    .Delete
    End With
    ActiveDocument.SaveAs FileName:=Docname
    ActiveWindow.Close
    Counter = Counter + 1
    Application.ScreenUpdating = True
    Wend

    End Sub</pre>


  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Keep Source Format (MS Word 2002)

    I assume the problem is that you are pasting from one document into a new blank one which has different styles defined. If this is not the problem then the following won't help
    'Add this to the top of the macro
    Dim aDoc As Document, aTemplate As Template, sTempPath As String
    Set aTemplate = ActiveDocument.AttachedTemplate
    sTempPath = aTemplate.Path & Application.PathSeparator & aTemplate.Name

    'replace the Documents.Add line with this line
    Set aDoc = Documents.Add(Template:=sTempPath)

    PS. You are likely to run into problems by not defining the documents you are working with. The above code only goes some of the way towards solving that problem.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •