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.
Note:
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.
Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!
The Mail Merge capabilities built into Word can appear limited at first glance. One thing that is often overlooked (and ...
Discover MoreWhen you merge information into a document, Word provides two different ways you can create your output. Here's an ...
Discover MoreWord has a great mail merge capability. Inherent in this capability is the option to send your merged documents via ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2018-03-15 05:36:59
Samson
ignore, I found that.
2018-03-15 05:01:27
Samson
My merged doc was in Lanscape orientation, after running those scirpts and all exported files becomes a portrait one?
Is there any way to maintain it's orientation?
2018-01-04 14:16:45
RaR
Instead of this:
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
This will work better:
ActiveDocument.SaveAs FileName:="test_" & i & ".doc"
Because if you run the same twice, the DocNum will be greater. If you use "i" then it will match the document section.
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
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!
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.
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2019 Sharon Parq Associates, Inc.
Comments