Merge Word Documents

How to Combine Multiple Word Documents into One Document

Wondering how to combine multiple Word documents into a single Microsoft Word document? Here's a simple way to merge Word documents in a directory.

Here's an easy way to merge all the Word documents in a folder into one Word document.

All you need to do is setup this simple Microsoft Word macro to merge many Word documents into a single Word document.

We are posting it here because it's not easy to find out how to do this. You can search for "Word merge documents in a directory" or "Microsoft Word merge documents macro" and a ton of variants and you might never find it.

So, hopefully you know how to setup a Word macro. Just add this macro for merging Word documents to your list of macros, then open a Word doc in the folder that has all your other Word docs, and run the macro. The macro loops through all the Word docs in the directory and combines them together. Voila! You're done.

Sub MergeDocs()
    Dim rng As Range
    Dim MainDoc As Document
    Dim strFile As String
    Const strFolder = "C:\Book\Chapters\" 'change to suit
    Set MainDoc = Documents.Add
    strFile = Dir$(strFolder & "*.doc") ' can change to .docx 
    Do Until strFile = ""
        Set rng = MainDoc.Range
        rng.Collapse wdCollapseEnd
        rng.InsertFile strFolder & strFile
        strFile = Dir$()
    Loop
End Sub

Share this article


Additional Resources for Entrepreneurs

Lists of Venture Capital and Private Equity Firms

Franchise Opportunities

Contributors

Business Glossary

 

Conversation Board

This macro should work for Microsoft Word 98, Word 2000, Word 2003, Word 2007 and all popular Microsoft Word versions. Was this macro for merging Word documents helpful? Please let us know.

  • shm posted on 8/17/2008
    shm
    I've created the macro as suggested. But I'm not sure what to do next. Is it correct that I put all the .doc files in one folder. Then what do I do next?
  • Ken Gaebler posted on 8/18/2008
    Ken Gaebler
    Yes, put all the .doc files in one folder. Make sure you changed the C:\Book\Chapters\ reference to your specific path on your PC.

    Also, you need the backslash at the end.

    Now, you can open any Word doc and run the MergeDocs macro. The Macro will create a new Word document and merge the contents of all of the Word documents in the specified folder into that new Word document. Then, save that Word document and you should be good to go. Good luck!
  • lizo posted on 12/12/2008
    lizo
    This macro worked perfectly for me! Thanks so much for posting. I just wanted to add a minor note; I believe the files to be merged in the folder are added to the new document in numeric and then alphabetical order, so it's a good idea to rename the files so that they will be in the correct order when the merge occurs.
  • niats posted on 1/5/2009
    niats
    thanks so much, worked wonderfully!
  • buzzermaster posted on 1/7/2009
    buzzermaster
    Isn't this easier? I opened the folder containing all the documents I wanted to merge. I created a blank Word document. Then I dragged the files from the folder and dropped them into the blank Word document, sat back and watched.
  • Not Quite posted on 1/15/2009
    Not Quite
    This macro combines the documents, but does not preserve each individual documents headers/footers, page margins, formatting, etc. Thanks anyways.
  • Yuri posted on 2/2/2009
    Yuri
    Awesome. Thanks so much. I was dreading the thought of merge each document one by one... The next thing would be to merge the docs into one and still have the individual ones linked to the master summary doc. That way edits can be done on an individual document level which would be reflected on the Master doc. But hey! I'll take what I can get for now. :-)
  • CFR posted on 2/6/2009
    CFR
    Thanks for the tip. It worked perfectly. Comment to Yuri: Using an older Word version (Word 2007 drives me nuts), I used to merge (link) several documents as chapters into one master file. There was a refresh function key you could press to update the master file whenever one of the linked files was edited. Word 2007 doesn't have that Insert File command anymore.
  • Traian posted on 2/7/2009
    Traian
    Thanks for the macro code. I combined 20 doc files without problem :)
  • Patrick posted on 2/22/2009
    Patrick
    It would be useful to include the entire process for creating this macro from scratch. For those of us who are unfamiliar with the Macro creation process. I tried looking the process up and creating it, but without success.
  • LG posted on 2/25/2009
    LG
    Fantastic! I merged over 4,000 documents! Thanks
  • CN posted on 3/17/2009
    CN
    Works, but I need to supply the order in which the docs should be merged. I was thinking of putting the doc in excel in the order I want them and then reading the excel doc in macro to supply order of docs. Any ideas how to do that?
  • Ken Gaebler posted on 3/17/2009
    Ken Gaebler
    I believe the default behavior for the Microsoft Word merge documents macro is to merge them based on an alphabetical sort of the filenames. So, if you need to supply the order of the docs, your best best may be to rename the docs so they are sequenced alphabetically in the order you want them. That would be easier than writing an Excel macro.
  • Sam posted on 3/18/2009
    Sam
    Hot damn !! Working like a charm - thanks
  • Di posted on 3/25/2009
    Di
    This did not work for me. I even tried the idea from "buzzermaster" but it turn out right. I need something that I can edit.
  • voross posted on 3/27/2009
    voross
    Thanks! worked perfectly! cheers
  • jon posted on 4/4/2009
    jon
    I have the same issue as CN. I have about 50 docs and need to select some or all of them in different orders for a new doc. I was thinking of having the list of doc names in excel and then number them in the order I want them then do the merge. Any thoughts?
  • Ken Gaebler posted on 4/4/2009
    Ken Gaebler
    Jon and CN, I threw a quick article together for you. It explains how to rename multiple Word documents at once. Hope that works for you.
  • kg posted on 5/4/2009
    kg
    I can try this but I need to take 50 documents and put them together and save them...edit them...and then rebreak them up the way they were originally...with edits included. is that possible?
  • Dave posted on 5/5/2009
    Dave
    This is great! However, is there a way to make this work where each doc it is taking will start on its own, new page? As a test, I ran this against 7 word docs, and it produced me a 5 page merged doc. Some of my initial docs were only a half page in length, so when combining, it just sort of truncated everything together. Does this question make sense? Thanks.
  • Ruth M posted on 5/19/2009
    Ruth M
    This worked great, except that I need to have each .doc on it's own page. What command do I add for the page break between each file?
  • Cg posted on 5/29/2009
    Cg
    Thanks for this it worked great! Do you know if there is a way to stitch an Excel document within these as well? Many thanks!
  • Mannoh posted on 6/1/2009
    Mannoh
    Thanks , worked perfectly.
  • Tz posted on 6/2/2009
    Tz
    Thanks a lot. Unfortunately, it didn't copy the headers and footers, which puts me back to square one. FYI, each of my docs. have different headers and footers.
  • echen posted on 6/2/2009
    echen
    how do you alter the micro with an OR statement to take both doc and docx
  • Christina posted on 6/11/2009
    Christina
    Genius!!! Thanks so much!
  • Lynton posted on 6/26/2009
    Lynton
    Love it! Thanks....
  • JD posted on 6/26/2009
    JD
    I entered the macro, ran it, and it produced a blank page. Not sure what to do.
  • Ken Gaebler posted on 6/26/2009
    Ken Gaebler
    JD, the macro should work. Doublecheck that you have the right folder path and that you specify .docx or .doc accurately based on your Word docs. Good luck!
  • Viz posted on 7/1/2009
    Viz
    Can somebody please give me more info about the procedure for implementing a Word macro? I am not so familiar with macros. The only thing I managed to do so far is to open a new empty doc. Thanks
  • jdomabyl posted on 7/28/2009
    jdomabyl
    Worked great for me. I used it to combime 577 different html documents into one Word doc.
  • TT posted on 7/30/2009
    TT
    That is great! However, greatly appreciate if any one of you could inform me on how to preserve (after merging the docs) each individual document headers/footers, page margins, formatting, etc.
  • BD posted on 8/6/2009
    BD
    This worked great for me. But I do need to just "merge" all the changes in updates submitted by different people into a baseline document. Can you help me change the macro to do that? I tried to find a function when the macro is in the Developer mode, but couldn't unfortunately. Any extra help will be appreciated!
  • lwss posted on 8/13/2009
    lwss
    But the Word doc formatting is changed. Is there any line that can be added to the Word macro to keep the Word formatting intact?
  • Emily posted on 8/27/2009
    Emily
    Hi, I have created the macro, saved it as a submerged file in the foler that contains all of the documents i want to merge and then opened one of the files and run the macro, but nothing happens. Please help.
  • Ken Gaebler posted on 8/27/2009
    Ken Gaebler
    Emily, that might happen if the macro is looking to concatenate Microsoft Word .docx docs and your files are actually .doc format Word documents. Make sure you replace .doc in the Macro with .docx or visa versa depending on what type of Word docs you have. Good luck!
  • dellfalconer posted on 8/31/2009
    dellfalconer
    Worked like a charm in Word 2000. Thanks!
  • evlindy posted on 10/6/2009
    evlindy
    How long should this process take? I created the macro, created a doc in the folder that has the 15 other docs I want to merge, ran the macro, and it seems to be taking quite a long time to process. Does it take some time to complete?
  • ladybug posted on 10/6/2009
    ladybug
    Works perfectly for files stored on a drive!! Is it possible to have this same function work for documents stored within a SharePoint document library?
  • ell posted on 10/6/2009
    ell
    I created the macro. I opened up a blank doc in the folder that contained the other docs I want to merge, but is did not work. I have .doc, so it isnt' looking for .docx. You mentioned changing the path, but I am unsure of what path to use, as it is a folder, within a folder, and several more folders deep. What path is it that I should use?
  • DB posted on 10/27/2009
    DB
    You know what would be great... modifying the script to also build a table of contents that indexes the insertion point of each document and uses the document name as the TOC entry. would that be hard to do?
  • TGS posted on 11/25/2009
    TGS
    Worked perfectly, Thank you
  • CH posted on 12/1/2009
    CH
    Worked perfectly! I kept getting a blank doc after running the macro because I forgot to put the \" ' at the end of my folder path. I was able to merge 34 documents into one. Thank you!
  • Nick posted on 12/1/2009
    Nick
    Worked great, only issue I had was kind of the same as Dave. I did this with several c++ files I had (just changed the extension to cpp instead of .doc or .docx) And most of my projects are relatively simple so they don't really hit the one page mark and I did this to have my code referenced on paper so things were easier for me to look up and it would be nice to not have to insert a lot of white space to make them go on each page. Either way, still worked so thanks!
  • Guilherme posted on 12/15/2009
    Guilherme
    Very helpfull Thanks a lot!!!
  • Tyler posted on 12/22/2009
    Tyler
    Much easier way is to open up a blank document then go to Insert, Object, Insert Text from File, then highlight all your files you want to combine.
  • Ken Gaebler posted on 12/23/2009
    Ken Gaebler
    Tyler, that's great to know. I tried it in Word 2007 and it worked for me. Much easier than using a macro. However, I'm not sure if it works in older versions of Word.
  • rob posted on 12/25/2009
    rob
    This macro does what it should do.It should be part of Word itself. Thanks for it.
  • Elizabeth posted on 1/1/2010
    Elizabeth
    This does not work in Pages. How does this work for Word for Macs?
  • Nicolas posted on 1/7/2010
    Nicolas
    Hi thanks for the post, but i got somme question, im not a VBA programmer, im c# programmer, but if i want to chose the parth of the document i want to merge, how can i do it? I have a userForm whit somme option and each option is a document to merge, I already creat a new word document, but i need to know how chose the path and how to import a single document at the time. Anyone!?
  • mathew posted on 1/21/2010
    mathew
    Help Did not work for me - no errors reported. All it does it opens a new word doc and stops. My win off is 03. -Mathew
  • mathew posted on 1/21/2010
    mathew
    Please ignore my last posting. It works! The failure to merge was caused by a space in the dir name - Thanks a bunch - Mathew
  • Catherine posted on 1/23/2010
    Catherine
    Thanks Tyler! That was so easy!
  • Desharri posted on 2/3/2010
    Desharri
    This is great. Thanks! I used it to combine a bunch of documents to run through a tag cloud generator. Next I get to figure out how to do it with mixed Office file types.
  • K Pugh posted on 2/8/2010
    K Pugh
    Here's a macro for merging a specific set of documents (Word 2007). It adds a page break after every merge, but you can take out that line.

    You just need to duplicate the lines for each document that you want to merge. The sequence in which you list them is the sequence in which they appear.

    Sub FullBook()
    '
    ' FullBook Macro
    '
    '
    Selection.InsertFile FileName:="Introduction - 03.doc", Range:="", _
    ConfirmConversions:=False, Link:=False, Attachment:=False
    Selection.InsertBreak Type:=wdPageBreak
    Selection.InsertFile FileName:="Introduction - 04.doc", Range:="", _
    ConfirmConversions:=False, Link:=False, Attachment:=False
    Selection.InsertBreak Type:=wdPageBreak
    Selection.InsertFile FileName:="Introduction - 05.doc", Range:="", _
    ConfirmConversions:=False, Link:=False, Attachment:=False
    Selection.InsertBreak Type:=wdPageBreak
    End Sub
  • dmonroe posted on 2/17/2010
    dmonroe
    Works great, except it puts a blank page at the beginning. FullBook() also works, except it uses the current document instead of a new document.
  • karthick Ramachandran posted on 2/26/2010
    karthick Ramachandran
    Hi , This code was amazing.My one man day work has been shrinked to two minutes work.Great work ! Suggestion : Please include a macro to rename multiple files by prefixing numbers along with the filename
  • Carsten posted on 2/28/2010
    Carsten
    The files are merged with Word 2007, but the formatting of the fonts (changed to default Word 2007 font), tables, and figures is changed. Is there any way to keep everything as is?
  • Damian posted on 3/2/2010
    Damian
    Not working unless Visual Basic is installed - pointless for me because I use Word Perfect anyway. regards Damian
  • Natascha posted on 3/5/2010
    Natascha
    What if I want to merge 2 documents and have the tracked changes maintained so that I can visually see them (in red). Also, I am not a programmer so a "click this click that" would be great.
  • vijay posted on 3/8/2010
    vijay
    Here's a variation of the macro that puts a page break after each document.

    Sub MergeDocs()
    Dim rng As Range
    Dim FinalEvidence As Document
    Dim strFile As String
    'Dim OutPut_file_name As String
    Const strFolder = "C:\Test\" 'change to any dir which you wanna use
    Set FinalEvidence = Documents.Add
    strFile = Dir$(strFolder & "*.doc")
    Do Until strFile = ""
    Set rng = FinalEvidence.Range
    rng.Collapse wdCollapseEnd
    rng.InsertFile strFolder & strFile
    strFile = Dir$()
    Selection.InsertBreak Type:=wdPageBreak
    Loop
    ' OutPut_file_name = "FinalEvidence.doc"
    End Sub
  • Nick posted on 3/9/2010
    Nick
    Thanks! Works Perfectly!
  • michael steven posted on 3/10/2010
    michael steven
    Will this work for me? I have 50 label files I prepared in Word. Each a separate file. They were prepared for a post card mailing project. The post card printer now tells me that he needs the labels in one file. Help
  • Chris posted on 3/17/2010
    Chris
    The macro works, but unfortunately I am trying to do something a bit different. What I want to do is to merge multiple documents, where each of the source documents represents a different person marking up an original. My task is to make a new master document incorporating all the comments from the various documents. You can do this one at a time in Word 2003 by going to "Tools" >> "Compare and Merge Documents", navigate to the file you want, then click "Merge". But I need a batch process! Something like "MergeFile" rather than "InsertFile", but, sadly, that doesn't seem to work
  • Melonie posted on 3/31/2010
    Melonie
    Forget using Macros - do doc merges with software. I just banged through 60 document merges using Bulk File Merger. I am not savvy with VB..so I needed a simple tool to do this somewhat trivial task.
  • hsb posted on 4/15/2010
    hsb
    how to first sort the doc files name wise and then merge those sorted files in to one doc file
  • PP posted on 4/29/2010
    PP
    How to preserve (after merging the docs) each individual document headers/footers, page margins, formatting, etc.?
  • VMB posted on 5/4/2010
    VMB
    Thanks for the macro. I am trying to do something even more complicated - I have several protected word forms, that I would like to merge together into one document. Any ideas on how to do that ? Thanks again !
  • cho posted on 6/2/2010
    cho
    how do you combine 2 different word documents with both document's track changes?
  • MS posted on 6/16/2010
    MS
    I am looking to extract the content of a word doc in a specific location and place the content onto another document. Is this possible? Thanks.
  • LEK posted on 8/17/2010
    LEK
    Excellent macro...be sure to enter the backslash at the end of the directory name...that threw me at first
  • Manoj jain posted on 8/18/2010
    Manoj jain
    It works perfectly. Can anyone guide me how to add "File Name" before adding the file in Bold letters.
  • JDW posted on 8/26/2010
    JDW
    how do I put pages from my computer 1 thru 188 onto a disk to make it one long page, I written a book and its in seperate pages so hard to pu on disk
  • Donna posted on 8/30/2010
    Donna
    I currently merge in word 2003 (coz I can't get to work in 2007!) a complete file consisting of covering letters, invoice, legal documents, certificates etc with up to 150 merge fields. How do I convert these to 2007?
  • Demmy posted on 11/19/2010
    Demmy
    Can someone tell me what I am doing wrong. I am trying to merge 14 documents into one, but am confused on the files I need to add. I have listed an example of what I am doing.

    Sub MergeDocs()
    Dim rng As Range
    Dim MainDoc As Document
    Dim strFile As String
    Const strFolder = "C:\Users\Desktop\Merge"
    Set MainDoc = Documents.Add
    strFile = Dir$([C:\Users\Desktop\Merge] & ["Doc1*.docx])
    Do Until strFile = ""
    Set rng = MainDoc.Range
    rng.Collapse wdCollapseEnd
    rng.InsertFile strFolder & strFile
    strFile = Dir$()
    Loop
    End Sub

    Tks,
    Demmy
  • Fermin posted on 11/23/2010
    Fermin
    THANK YOU!!!!
  • Arne S posted on 12/14/2010
    Arne S
    I have modified the macro to insert Word documents as images instead of formatted in order to preserve formatting. The inserted document is still handled as text in relation to filesize and printing but it is not editable. Only tested for inserting one page documents. The inserted document will be slightly smaller than the original due to margins.

    Sub MergeDocumentsAsImages()
    Dim counter As Integer
    counter = 0
    Dim rng As Range
    Dim MainDoc As Document
    Dim strFile As String
    Const strFolder = "C:\Book\Chapters\" 'change to suit
    Set MainDoc = Documents.Add
    strFile = Dir$(strFolder & "*.docx") ' can change to .docx
    Do Until strFile = ""
    Set rng = MainDoc.Range
    rng.Collapse wdCollapseEnd
    If (counter > 0) Then
    Selection.InsertBreak Type:=wdPageBreak
    End If
    counter = counter + 1
    Documents.Open FileName:=strFolder & strFile, ConfirmConversions _
    :=False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
    PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
    WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
    Selection.WholeStory
    Selection.Copy
    ActiveWindow.Close
    Selection.PasteSpecial DataType:=wdPasteMetafilePicture
    strFile = Dir$()
    Loop
    End Sub
  • H posted on 12/23/2010
    H
    Didn't work with Word 2002. Just give me a blank 1 page
  • Arthur posted on 1/3/2011
    Arthur
    To everybody that is getting the blank page... on the line code: Const strFolder = "C:\Book\Chapters\" 'change to suit don forget to add the backslash at the end of path, like in the example... if you change to a folder on your JohnDoe user desktop, it should be something like... Const strFolder = "C:\users\JohnDoe\desktop\" 'change to suit Happened to me to... :)))
  • princess posted on 3/7/2011
    princess
    hi friends i'm trying from afternoon and couldnt solve this. still i'm getting a blank page even after putting the back slash at the end. i have saved it in the folder named new in f drive and named it as F:\new\. should any change done to this? should we specify a new name in the next line of code? Plz...help me. its urgent
  • Ken Gaebler posted on 3/7/2011
    Ken Gaebler
    Princess, are you docs *.docx Word documents or *.doc Word documents. In the code, where it says "*.doc" you need to make sure that matches your type of Word document. If that doesn't work, post your code and I will help you out.
  • princess posted on 3/8/2011
    princess
    i'm using MS word 2007 and saving it as 97-2003 and now i added the extension as*.docx and changed it in the in the code too as *.docx. i hope i saved earlier as *.doc. what mistake am i doing in this? plz help me
  • Sandy posted on 3/8/2011
    Sandy
    Princess, we can't help you if we can't see your macro code. Paste it into a comment for us.
  • princess posted on 3/8/2011
    princess
    i have used the same code as given here. i have pasted it here
    Sub MergeDocs()
    '
    ' MergeDocs Macro
    '
    'Dim rng As Range
    Dim MainDoc As Document
    Dim strFile As String
    Const strFolder = "F:\new\" 'change to suit
    Set MainDoc = Documents.Add
    strFile = Dir$(strFolder & "chapters.docx") ' can change to .docx
    Do Until strFile = ""
    Set rng = MainDoc.Range
    rng.Collapse wdCollapseEnd
    rng.InsertFile strFolder & strFile
    strFile = Dir$()
    Loop
    End Sub
  • Ken Gaebler posted on 3/8/2011
    Ken Gaebler
    Princess, I see two mistakes. First, you have an apostrophe in front of "Dim rng As Range" and you shouldn't. An apostrophe turns a line into a comment that is effectively ignored. Second, and more importantly, you have chapters.docx where you should have *.docx -- the * or asterisk is critically important to this macro and needs to be left intact. An asterisk is a wildcard, so *.docx tells the macro "find any file that ends in .docx for me and use those files in the merge." Once you changed that to chapters.docx, your code was no longer looking for many files; rather, it was looking for one file called chapters.docx. Hope this makes sense. Good luck. Don't forget -- newer versions of Word have a merge/combine feature. If you continue to have troubles, I would suggest you upgrade to a newer version of Word.
  • princess posted on 3/9/2011
    princess
    thank u friends.. i corrected my mistakes and now its working wel..really its very useful. thanks a lot..
  • pizdek posted on 3/14/2011
    pizdek
    this works great, but it would be useful to have macro with reverse operation, one that would split large document into separate documents - each page of large document is one new document called like the first word on that page... do you maybe have that kind of macro? thanks in advance!

Leave a Reply

Questions, Comments, Tips, and Advice

Email will not be posted or shared
Code Image - Please contact webmaster if you have problems seeing this image code

Problem Viewing Image? Load New Code