Word images - mail merage

Posted on 2008-11-20
Last Modified: 2016-08-30

I have a word document that mail merges various charts onto two pages.  Each of the pages has a pupil name.  I what to create seperate documents for each pupil.  So I want to be able to split merge document into seperate files each containing two pages with the title being the pupil name or set up some sort of macro that will insert the images and then save the document.

I have attached the merge file to show what the layout is.  The merge code I am using is similar to
{INCLUDEPICTURE "c:\\TargetCharts\\{MERGE FIELD PupilID}TC.gif"}

I hope this makes sense.  Thanks,

Question by:DesiMck
    LVL 76

    Accepted Solution

    I am unclear about the nub of the problem. Is it about images as the title suggests? You seem to have that covered.

    You can produce separate documents in a couple of ways. You can either run a single-record merge or you can split the document afterwards. Provided that you don't have any section breaks in the main document, the latter is fairly simple.

    This macro splits the result document at the section breaks and saves each part as a document named from the text at the beginning of the section (up to the first tab).

    Sub SplitMergeResult()
        Dim sec As Section
        Dim rng As Range
        Dim strName As String
        Dim DocA As Document
        Dim DocB As Document
        Set DocA = ActiveDocument
        For Each sec In DocA.Sections
            Set rng = sec.Range
            rng.MoveEnd wdCharacter, -1 'omit section break
            strName = Split(sec.Range.Paragraphs(1).Range.Text, vbTab)(0)
            Set DocB = Documents.Add
            DocB.SaveAs strName & ".doc"
        Next sec
    End Sub

    Open in new window

    LVL 1

    Author Closing Comment

    Thank you for your excellent and speedy reply.  This solution worked.  Sorry for the over complication in my question and the rather misleading title.

    Expert Comment

    by:Jamie Gash
    I need to control the filename of the newly created sperate document. Ideally I'd like to use a mail merge field from within the document (Clients Account Number). Can you explain how I edit line 13 (I assume) to make this work.
    LVL 76

    Expert Comment

    You would need to locate the text somehow on the document. How you do that depends on the document and your skills,

    If any further advice is needed, please raise your own question.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
    If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
    This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
    Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now