# Shkenca > Informatikë dhe Internet > Arti i programimit >  VBA code (macro) per mail merge!

## ahmed_tr

prsh!

Kam nje problem me mail merge, pasi perfundoj mail merge qe te me ndaje cdo rekord ne dokument me vete me nxjer nje flete teper ne cdo dokument.
ne vijim codi macro:


```
Sub SplitMergeLetter()
' 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:\My Documents\Test\Merge\" & sName & ".doc"

     ActiveDocument.Sections.First.Range.Cut
     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
     ActiveDocument.SaveAs FileName:=Docname, _
     FileFormat:=wdFormatDocument
     ActiveWindow.Close
     Counter = Counter + 1
     Application.ScreenUpdating = True
Wend
End Sub
```

flm per cdo informacion.

----------


## valdetshala

te kisha keshilluar te postosh ne http://www.forumishqiptar.com/forumdisplay.php?f=161
te arti i programimit

----------


## ahmed_tr

Le ta kalojne si teme administratoret.

----------

