Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, and 2013. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Merging to Individual Files.

Merging to Individual Files

by Allen Wyatt
(last updated January 16, 2014)

19

When you use the mail-merge feature in Word, you have the option of either printing your results directly or creating a new document. If you choose the latter option, the resulting document contains all the information that normally would have gone to the printer. For instance, if your merge document is a two-page letter, each letter in the resulting document is separated by a section break. Thus, if you are merging the two-page letter with 150 different addresses, then you would end up with a 300-page document with 150 section breaks (one every two pages).

For some people, it would be more helpful if you could merge to individual files. For instance, given the above example you might want 150 individual document files, each two pages long. Unfortunately, that is not one of the options available when using Word's mail-merge feature. The only answer to accomplishing this task is to create a macro that will, based on the merged document (the 300-page one mentioned above) take each section and save it to its own document file.

If you look in Microsoft's Knowledge Base, you will find that there is an old article that deals with this very issue:

http://support.microsoft.com/kb/216201

The macro presented in the article, even though it was written for Word 97, will work just fine in Word 2007 and later versions. It allows you to separate a merged document into individual files, based on the section breaks:

Sub BreakOnSection()
    'Used to set criteria for moving through the document by section.
    Application.Browser.Target = wdBrowseSection

    'A mailmerge document ends with a section break next page.
    'Subtracting one from the section count stop error message.
    For i = 1 To ((ActiveDocument.Sections.Count) - 1)

        'Select and copy the section text to the clipboard
        ActiveDocument.Bookmarks("\Section").Range.Copy

        'Create a new document to paste text from clipboard.
        Documents.Add
        Selection.Paste

        'Removes the break that is copied at the end of the section, if any.
        Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
        Selection.Delete Unit:=wdCharacter, Count:=1

        ChangeFileOpenDirectory "C:\"
        DocNum = DocNum + 1
        ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
        ActiveDocument.Close
        'Move the selection to the next section in the document
        Application.Browser.Next
    Next i
    ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub

It is important to realize, however, that this macro will only work if the only place that section breaks occur is between merged documents. If your original document includes section breaks, then the macro will not provide satisfactory results. For additional information on using the macro, refer to the Knowledge Base article at the link provided above.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (8435) applies to Microsoft Word 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Word here: Merging to Individual Files.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Zooming In On Your Worksheet

If you have trouble seeing the information presented in a worksheet, you can use Excel's zooming capabilities to ease the ...

Discover More

Excluding a Specific Add-In at Startup

Got an add-in that you don't want loaded each time that Excel starts up? Here are a few ways that you can exclude it.

Discover More

Smart Quote after Em Dash Faces Wrong Direction

When using smart quotes in your typing, Word tries its best to figure out which way the quote you just typed should face. ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Merging Formatted Data

Using the mail merge feature of Word, you can make data from Access databases accessible for your documents. How information ...

Discover More

Mail Merge and Data Source Documents become Unattached

When you create a mail merge document, you attach it to a data source that is the basis for the information to be merged with ...

Discover More

Automatically Determining a Due Date

When you are doing a mail merge in Word, you may need to calculate a date sometime in the future. Word doesn't include an ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five minus 4?

2017-07-31 12:04:35

Jennifer

Could you add to this how to create the macro using the text above? How would I record this?

Thanks!


2017-01-18 14:58:43

Mike

How do you execute this code? I'm familiar with excel VBA but there is no option to 'run' in Word.

I'm also trying to run this in Word 2013 (not sure if it matters).

Thank you in advance!!
Mike


2016-12-06 17:01:30

Tony

This works great.. however, how do we pull the header too?


2016-09-12 15:09:00

Simon Odell

Hi,

This Macro works great however I lose all formatting once running it.

It turns most of the font bold and then adds loads of extra spaces between paragraphs.

Is anyone aware of a solution to this?

Thanks


2016-08-18 10:38:38

crazypig

Great stuff. Easy, quick and effective. I'm not going to bother trying to name each letter based on something within the letter. numbering them will do fine.

thanks.


2016-03-05 07:14:57

vmgreek

I used this macro just the other day and it worked fantastically. It saved me a bunch of time.

I only ran into 1 issue: where I had arranged a list into columns on the master merged document prior to splitting, I guess Word looks at columns as sections, and it actually split the second column into a separate file so I had to copy the info back into the file in which it belonged. I would therefore suggest you make those kinds of modifications after you split the file.


The main thing I noticed is that the extension now needs to read docx since it saved everything out to .doc it looked like older versions. It was no big deal for me, but when I put them on SharePoint, which is what I needed them for, the users had to convert the files, which was a little weird. So I changed it.

I saved the macro into my normal.dotx file so that I can use it in the future.

To answer some of the questions on this post: you just run the mail merge as normal. Then you run the macro.


2016-01-20 04:18:13

PeterFH

I do not really use macros usually, thus this question might seem silly, but is there a way to set one of the merged details - such as a project number - as the name of the individual file created?
E.g. I have projects 123, 124, 130 etc. and after the merge I get 123.doc, 124.doc, 130.doc..


2015-08-05 05:32:46

Choudhary

Hello everyone,
I am trying to run this Macro, but there is an error coming up with 5156 number. It is in the line towards the end
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"

I am using word 2010. Any help will be hugely appreciated!
Many thanks
Cherers


2015-07-23 09:20:58

Garyu Novak

How do we get DaveV's macro? This is exactly what I am looking for
Thanks!


2015-06-02 10:20:18

SG

I am really not able to run this macro.. do we have to add separate code for mail merge?, becoz everytime i run this, it only gives 1 file as an output, which is the 1st record of the XL file.

Steps I am doing:
- Merge the doc with XL file fields
- Create the fields in doc and dry run to check the data is coming fine
- add the section page break
- copy the code in VB editor and save file as .docm
- then select the data in document and run the macro..

VOLA - only 1 page comes out as an output


2015-05-07 12:06:05

AW

Is there anyway I can run this without individual documents opening? I've got 2000 that I really don't want popping open on my pc.


2014-10-28 22:31:29

Pia

The above macro is great, I would like to add a piece of code that applies a file name to each file rather than a #. Ideally this would be pulled from the merged letter, so that I can relate each letter to a person by the file name. Does anyone have any ideas?


2014-10-15 16:00:51

B. Urick

Thanks for this posting. I ran into an issue where I wanted to create 100+ individual merged documents then print them consecutively with staples.

The max number of documents that can be selected in Windows 7 is 15, so this was going to be a pain to select 15, print, repeat.

Solution:
Add a print command into the macro.

This may seem obvious to experienced users, but this I am just starting.

Here is my modification:

...
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
ActiveDocument.PrintOut
ActiveDocument.Close
...

Worked great. It uses the default printing settings, just like batch printing from the menu.


2014-09-08 02:04:27

Melissa

I had been trying all sorts of macros until i tried this one and I must say it was AMAZING! This is the BEST macro ever. Splits files into individual files with such less effort. Thank you so much!


2014-08-24 00:13:30

Sajan

Have you looked at Graham Mayor's pages for splitting merged document to individual documents?

http://www.gmayor.com/individual_merge_letters.htm


2014-06-04 15:41:29

Sally

I'd like to get detail from DaveV response...save each resulting with naming convention from mail merged document?


2014-02-18 09:14:47

Susan

DaveV, I beg you! Can you possibly share what you wrote for this? It's exactly what I need to do. I am so new at this that it's driving me nuts!


2013-09-05 09:46:27

DaveV

This solution from MS did not help me. Instead I ended up creating a process/macro where I setup the mail merge as normal (manual process) but then run a macro that does the actual merge generation process. It runs the mail merge process for one record at a time and saves each resulting file with the naming convention that I want (using info from the mail merge document). In this same saving process I am also able to create PDFs. Wish MS would put this type of option on the knowledge base.


2013-08-14 15:52:54

J. Mason

Hi!

I'm a newbie. How do you use the macro? Do you create the mail merge and then run the macro? Do you create the mail merge any differently than usual?

Thanks!


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.