View Single Post
 
Old 01-11-2013, 09:41 AM
Baldeagle Baldeagle is offline Windows XP Office 2007
Advanced Beginner
 
Join Date: Apr 2012
Posts: 62
Baldeagle is on a distinguished road
Default Mailmerge to Email with a mailmerge attachment

I got help last May on this subject and the result was successful. I am now trying something similar but different. The following is the Macro which I used previously but this time it says that there is a problem at the section highlighted in red. The only difference that I can see is that my merged documents have 2 pages each whereas last year there was only one. Is this the cause of my problem and if so how do I modify the Macro to keep the 2 pages together when it does the split?
Code:
Sub SplitMergeForm() 
     '
     ' 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 
    Dim docName As String 
    Dim Letters As String 
    Dim Counter As Long 
    Dim oDoc As Document 
    Dim oNewDoc As Document 
    Set oDoc = ActiveDocument 
    oDoc.Save      
    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 = "C:\Our Folders\IMAP\Form " & sName & ".doc"          
        oDoc.Sections.First.Range.Cut 
        Set oNewDoc = Documents.Add          
         'Documents are based on the Normal template         
         'To use an alternative template follow the link.
        With Selection 
            .Paste 
            .HomeKey Unit:=wdStory 
            .MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend 
            .Delete 
        End With 
        oNewDoc.SaveAs FileName:=docName, _ 
        FileFormat:=wdFormatDocument, _ 
        AddToRecentFiles:=False 
        ActiveWindow.Close 
        Counter = Counter + 1 
        Application.ScreenUpdating = True 
    Wend      
    oDoc.Close wdDoNotSaveChanges      
End Sub

Last edited by macropod; 02-05-2013 at 08:21 PM. Reason: Added code tags & formatting
Reply With Quote