Link to home
Start Free TrialLog in
Avatar of Sheils
SheilsFlag for Australia

asked on

Splitting Mail Merged Documents in Word using Macro code?

an anyone tell me how to write - using text - a macro in word - I have code that will split a mail merge into individual docs but don't know how to use it?


Sub Splitter()
    Selection.EndKey Unit:=wdStory
    numlets = Selection.Information(wdActiveEndSectionNumber)
    If numlets > 1 Then numlets = numlets - 1
    Selection.HomeKey Unit:=wdStory
    BaseName = "c:\Let"
    For Counter = 1 To numlets
        DocName = BaseName & Right("000" & LTrim(Str(Counter)), 3)
        ActiveDocument.Sections.First.Range.Cut
        Documents.Add
        Selection.Paste
        Selection.MoveLeft Unit:=wdCharacter, Count:=1
        Selection.Delete Unit:=wdCharacter, Count:=1
        ActiveDocument.SaveAs FileName:=DocName
        ActiveWindow.Close
    Next Counter
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sheils

ASKER

Jeff

My apology. This is a question that a friend of mine was working on. I believe that she has already sorted it out. Sorry for wasting your time

Regards

SB9
No waste of time.

I thought it was an interesting question.

If you post the solution you can ask that your own answer be accepted instead of mine.
I am interested in the resolution.
(Remember, I don't need the points)
;-)

Besides, my post was not a solution, so I don't deserve any points anyway...

;-)

Jeff