Thread: [Solved] Use of Macro SplitMergeForm
View Single Post
 
Old 07-17-2014, 08:37 AM
Baldeagle Baldeagle is offline Windows 8 Office 2013
Advanced Beginner
 
Join Date: Apr 2012
Posts: 62
Baldeagle is on a distinguished road
Default Use of Macro SplitMergeForm

Last year I got considerable help in sending emails with 2 attachments. This year I have hit a snag. When I merge one of my attachments (see A) into a document with all the different individual forms in one document (see one such form in B) there is some distortion of the layout. But when I use the Macro SplitMergeForm it distorts the layout even more (see C which is the form to be attached to the emails).

Is there any way that the original layout can be maintained for the attachment?

My macro is as follows -
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\BWMC\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
Attached Files
File Type: doc A.doc (55.5 KB, 11 views)
File Type: doc B.doc (54.5 KB, 10 views)
File Type: doc C.doc (55.5 KB, 9 views)
Reply With Quote