View Single Post
 
Old 02-06-2013, 04:51 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit 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

Both your Word document and the pdf would take a fair bit of effort to convert to a Word document that doesn't use textboxes/frames. Try the following:
Code:
Sub SplitMergeForm()
    'Application.ScreenUpdating = False
     '
     ' SplitMergeForm Macro
     '
     ' splitter Macro modified to save individual Gift Aid (and Tax) Allocation Forms with
     
     ' information from data source. The filename data must be added to
     ' the top of the merge letter - see web article.
    Dim sName As String, docName As String
    Dim oDoc As Document, oNewDoc As Document
    Dim Rng As Range
    Dim i As Long, j As Long
    Set oDoc = ActiveDocument
    With oDoc
        j = .Sections.Count - 1
        For i = 1 To j Step 2
            Set Rng = .Sections(i).Range.Paragraphs.Last.Range
            With Rng
                .End = .End - 1
                sName = Replace(.Text, ".", "_")
                .Delete
                .Start = .Sections.First.Range.Start
                docName = "C:\Our Folders\IMAP\Form " & sName & ".doc"
                .MoveEnd wdSection, 2
                .Copy
            End With
            Set oNewDoc = Documents.Add
            With oNewDoc
                With .Range
                    .Paste
                    .ParagraphFormat.SpaceBefore = 0
                    .ParagraphFormat.SpaceAfter = 0
                End With
                .SaveAs2 FileName:=docName, FileFormat:=wdFormatPDF, AddToRecentFiles:=False
                .Close wdDoNotSaveChanges
            End With
        Next
        .Close wdDoNotSaveChanges
    End With
Application.ScreenUpdating = True
End Sub
Each output document will have an empty extra last page, but that's unavoidable unless you create a template that preserves the page layout, for calling via the Documents.Add process.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote