Merge Multiple Word 2010 Documents

Unarguably Word 2010 is a best word editor around, apart from providing basic editing tools and charting styles, it also provides an option to customize document in any way you want. Concealed by default, Word 2010 provides an option to add different functions, like for example, by inserting few lines of code you can merge Word documents without having to use any dedicated third party app. In this post we will be inserting few lines of code to merge all contents of documents residing in the same folder and show them in a new one.

To begin, first you need to put them in the same folder, make sure that they all belong to same Word version either Doc or Docx. As you can see in the screenshot below, we have opened two documents that will be merged together.

two documents

Now open any Word document and save it as Macro-Enabled document, for this, go to File menu and click Save As.

save as

A dialog will appear, from Save as type, click Word Macro-Enabled Template and click Save.

dotm

We will be using VB editor, so first we need to make Developer tab apparent on Word window. In case you don’t find Developer tab, go to File menu, click Options, and in left pane click Customize Ribbon, from right pane enable Developer check-box. Click OK to to see Developer tab on the ribbon.

developer 1

Now navigate to Developer tab and click Visual Basic.

developer

You will reach VB Editor dialog, from left sidebar double-click ThisDocument to open it’s VB editing window. You will see the code window on the right side. Now put these lines of code in it.

Note: Don’t forget to change the path of the folder where the documents are residing and version of Word documents in these lines of code. To make it easier we have added this precaution in front of the codes as well.

Sub MergeDocs()

Dim rng As Range

Dim MainDoc As Document

Dim strFile As String


Const strFolder = “C:\Users\Usman Javaid\Desktop\Word documents\” ||| (Change the path where your documents are residing)

Set MainDoc = Documents.Add

strFile = Dir$(strFolder & “*.docx”) ||| (Change file extension to .doc incase you are dealing with Word 97-03 version)

Do Until strFile = “”

Set rng = MainDoc.Range

rng.Collapse wdCollapseEnd

rng.InsertFile strFolder & strFile

strFile = Dir$()

Loop

End Sub

vb editor

Now press Ctrl+S to save the newly added macro and close the VB editor. Navigate to Developer tab and click Macros.

macros

From the Macros dialog, select MergeDocs macro and click Run.

macros 1

If you have specified path and version correctly, then all documents would merge and open-up in a new document.

merged

You can also check out our previously reviewed guides on Return to last line edited in Word 2010 and using Mail Merge in Word 2010.

[via gaebler]

Advertisement
  • Joshua

    Can’t you just go to the Review Tab>compare>merge?

    • Usman

      Yes you can do that from built-in Combine (Merge) option but it would combine two different versions of document. This post elaborates how to merge multiple documents residing in same folder. All you need to do is place the documents in one folder (which you want to merge), make a macro and it would merge all the documents…

  • Pingback: Combine Different Versions Of Two Documents In Word 2010

  • J kramer

    @joshua the combine feature will only combine TWO docs….

    @Usman
    Thankyou for sharing this wonderful tip..i have just merged 27 documents…looking for this one….

  • http://www.stakeholdermap.com T Morphy

    Hi,

    Thank you for this great article. Only problem is I am getting an compile error for the file path I entered for strFolder.

    Const strFolder = “C:\Users\Usman Javaid\Desktop\Word documents\”

    Expected: Line number lable or statement or end of statement.

    • Bhupinder

      Hi Morphy,

      You need to change the style of paranthesis. It should work then. Also make sure that you are adding “\” sign at the end of files locaiton.

  • eilon

    for some reason it is not working as expected. it just results with a blank single page word document.

  • A. Einz Tein

    kool this is the right way to do it. you rule man.

  • Connor

    I eventually got it to work, but a couple things tripped me up and it looks like they tripped other people up from this thread. First, if you copy/paste from the code above, you will have “smart quotes” (the kind that are different for the open quote and the end quote). You need to replace these with “dumb quotes”–the kind that go straight up and down or you will get a syntax error. Second, you have to make sure that you have a “\” at the end of the path, or you will just generate a blank document.

    Thanks for the handy tool!

    • Tarah

      Great! Fixed the problem

  • snook

    everytime i am getting blank pages.
    this tool work to combine my 313 docs,
    get this tool from http://www.softlay.org/combine-documents.html

  • John Dougherty

    What if I wanted to insert a line of text that appears in-between each inserted document, or literally what I am wanting to do is insert the name of document that is currently being merged in, so that it appears at the top of the text of the document currently being merged in?

  • Mario

    Anybody know if there’s a macro that basically lets you combine revisions from several authors into a single document? You can do this with Word’s “combine” function, but it only allows you to combine two documents at a time. I need something that would allow me to combine several documents at once.

  • Jack

    I also get a syntax error. You need to get rid of everything after the 3 vertical lines i.e.

    Const strFolder = “C:\Users\Usman Javaid\Desktop\Word documents\” ||| (Change the path where your documents are residing)

    should just be

    Const strFolder = “C:\Users\Usman Javaid\Desktop\Word documents\”

    Otherwise you’ll get a syntax error.

  • Dave Dragon

    Great starting point!
    I added a macro to globally set the font and size as well as name and save the merged document.

    I’m combining 27 separate documents (chapters) into one document (manuscript) and this makes it easy to edit a chapter and recombine the manuscript.

    Thanks

  • Mary

    For some reason mine is not working. I am confused as to what I replace this with

    strFile = Dir$(strFolder & ” * .docx”)

    All my files are 2010 so I just deleted the last part. I keep getting “can’t execute code in break mode”?? What does that mean and how do I fix it to merge the documents?

    • B Arnot

      Hi Mary, 

      Did you get an answer to this question? I can’t seem to get it to work either. I have exactly the same problem. 

      Cheers, 

      Ben

      • B Arnot

        Ha, just worked it out… close the Visual Basic program before trying to run the Macro… But now I’m getting a blank document. Will have to keep reading the comments… 

  • JennyH

    Thank you, excellent instructions. Initially, I also had problems similar to those outlined above. However, after changing the smart quotes for dumb quotes AND making sure that there were no additional spaces in this bit: “*.docx” , all worked perfectly well. (This last was important – before that, I got an empty one page document. When I copied the text from the web, in addition to smart quotes, I had blank spaces before and after the * ).

    • Maria

      I was having similar problems until I read your posting about eliminating spaces. Thank you so much!

    • Derek

      Thank you for clarifying this. After implementing your suggestions it worked like a charm!

      My path was to
      1. Change Smart Quotations into Dumb Quotations
      2. Eliminating the spaces
      3. Sigh of relief when my 300 documents merged together.

    • Jr

      Thanks sooo much. I was having the “blank page” problem until I took the spaces off the *.doc section. Cheers!

    • Kim

       JennyH, thank you so much for adding the ‘remove spaces’ comment!! (And USMAN–I could KISS YOU FOR THIS!)

      • Michelle

        Appreciate your comment above. Worked OK, but I am merging documents full of labels and when it merges it loses all the formatting. Any ideas how to maintain the formatting of the original documents?

  • Steve Audus

    This is a great macro, worked when I replaced “ with ”
    I’m merging xml files.

    2 quick questions

    1) How do you add a page break between documents?
    2) Why does it reformat my tables in the documents, so they fall off the page.

    Thank you for any help.

    • Maxtesting

      Merge with page greak:

      Sub MergeDocs()

      Dim rng As Range

      Dim MainDoc As Document

      Dim strFile As String

      Const strFolder = “H:Dokumentyjuniorstav 2011 1.2″

      Set MainDoc = Documents.Add

      strFile = Dir$(strFolder & “*.doc”)

      Do Until strFile = “”

      Set rng = MainDoc.Range

      rng.Collapse wdCollapseEnd

      Selection.InsertBreak Type:=wdPageBreak

      rng.InsertFile strFolder & strFile

      strFile = Dir$()

      Loop

      End Sub

  • Nico

    Thanks very much, it eventually worked, but I had to read the comments before I could manage. For some strange reason every time I saved my VB work, spaces started to appear in the strFile = Dir$(strFolder & ” * .docx”) part of the code, I first had to reduce it to strFile = Dir$(strFolder & ”*.docx”) before I had success.

  • Jacob Hantla

    Thank you. With the help in the comments it eventually worked…but unfortunately lost much of the formatting and combined headers along the way so it didn’t end up being functional for my needs.

    • B Arnot

      I had the same problem. Did you find an answer?

  • Rich

    Does anyone have a simple macro that will combine multiple word documents that are open into one document (without saving them)?

    Many thanks!

  • nick

    Im getting a “Object variable or With block variable not set” error. does anyone know how to solve this?

  • Josh

    This is working for me, but I’m not sure how to get the documents to add in a specific order. How are they sorting before they are added, and is there a custom way to sort them? Like by filename or something similar?

  • Mosby

    You can achieve the same result directly in Word without any macros or coding. See
    http://www.mydigitallife.info/combine-and-merge-multiple-documents-in-microsoft-office-word-2007/

    Just remember to select your files in the REVERSE order you want them to appear in the document.

  • Josh

    QUESTION:

    Currently I have the documents in my library named like the following:

    2011-01-March-Doc 1
    2011-02-March-Doc 2
    2011-03-March-Doc 3

    But they are not being combined in that order… so I don’t know if its alphabetically, but I’m not sure why it’s not sorting correctly when it combines the documents…. any ideas? Or maybe a way that I can specify a sort type in the macro code?

    • Annalamky

      I have the same problem, I find that merging >10 doc at a time helps. Of course, its really no help at at when your report runs 100 over pages…

      • DonaLuisa

        Has anyone had success ordering of the combined documents? My files are in the same folder and named–
        Test_1.docx,
        Test_1a.docx,
        Test_2.docx,
        Test_A.docx,
        Test_B.docx,
        Test_C.dox, and
        Test_D.docx.

        Here is the order they list in the combined document:
        Test_D
        Test_1
        Test_2.docx
        Test_3
        Test_A
        Test_B
        Test_C
        Test_1a

        They don’t match Data modified either.

  • Melissama

    Fantastic tips and points!! just had to make slight changes as everyone else seems to have done and all worked :)
    Than k you so much!!!

  • Ronald

    Thanks for the macro code. Just merged 132 docs to 1.

  • Afrin

    thnx this macro worked. I got all the documents merged but the lose the formatting. two different documents are starting from the same page. How to insert page break between separate documents?

  • http://www.quizmantra.com Puja

    Its working for me. Thanks for saving a hell lot of my time.

  • Anonymous

    This works! But, I have some questions that will probably expand the code. First, I want a section break between each document that in merged. Pluse I want the page numbering to change based on the section. ie. the first paragraph of each section has a bookmark that is added as a prefix to the page number in the footer.

    • Lopita

      A page brake can be added by inserting this code before line rng.InsertFile as follows:

      Selection.InsertBreak Type:=wdPageBreak rng.InsertFile strFolder & strFile

      …it’s worked for me

      • http://www.facebook.com/profile.php?id=16736601 Shannan Godbey

        I need to insert page breaks too, but I got a Syntax error with this…can you help?

  • http://twitter.com/iivanovbg Ivan Ivanov

    very nice indeed but it is smashing the tables all around

  • Guest123

    How can it be ‘a best word editor around’ if it is that complicated to merge two simple documents…

  • Guest123

    How can it be ‘a best word editor around’ if it is that complicated to merge two simple documents…

    • peta

      I totally agree. It does EVENTUALLY work once you mess about tweaking this and that, sticking spaces in, page breaks, parentheses, the right kind of quotation marks, etc., etc., but then ONLY if the documents you are merging are straightforward text docs with no headers or footers or anything much else.
      If this is as good as it gets, we’re in real strife!!!

  • AndyW

    Doesn’t work for me.  Throws a syntax error on the “Const strFolder” line no matter what I enter in as the path.  I am no VB expert but have programming experience in VB and C# but can’t figure out why it wants “Expected: line number or label or statement or end of statement”.  FYI, it throws this error at the slash after “C:”.

  • Aja9fu

    Can’t I do it without being a rocket scientist.

  • Pinhead detector

    What horse shit.  PDF’s drag and drop and you’re done.  This is a fucking nightmare for a simple task.

    • peta

      I am so with ya mate!!!

    • J

      Probably the best comment ever….

    • Joe

      All this advice (as well as this article) is horrible. Simply select the documents in Explorer and drag and drop them into a new Word document. It will combine everything without issue. All this VB nonsense is totally unnecessary.

      • Chris

        Thank you for this post… I was half way through the directions above!

      • KT

        Be thankful someone spent a lot of time to make our life easier. No need for negative comments.

        Are you going to drag and drop hundreds of documents everyday?

  • Gerd

    the best word editor shouldnt require this convoluted procedure to merge documents! just another proof point that this product totally sux!

  • Guest1

    Is there anyway to keep the headers of the different documents you are merging as well? This will merge the documents with the correct page breaks and such but it doesn’t allow the different headers throughout the new document. It just keeps the first one. 

  • Pozzuto 4

    Help I read through all of the comments and this still is not working for me…..

    • Tester

      i had to replace the quotes then it worked for me.  (all the quotes in the code)

  • Hassini77

    Absolutely brilliant!!! I needed to combine 36 word documents into one. This was a HUGE time saver. Thank you, thank you, thank you!!!

  • Annalamky

    Hi, thanks for posting this up. Up until now, I’ve been using the ‘insert text’ button which tends to mess up the formatting.

    This method works great, except for the pages tend to mess up. So I’d get page 10, 11, 12, 13 then 1, 2, 3, 4.

    Does anyone know why? 

  • Daisy

    Hello – I applied your macro and it worked brilliantly. Only problem is, my document now won’t save…. I press save (or save as), it tries for a few seconds then pops back up with the save as window. Any ideas?? I’ve tried a few different formats and different locations and nothing has worked…

  • Peter

    Excellent! After following all of the comments about spaces, quotes, etc. it worked great!

  • http://pulse.yahoo.com/_DZNUF3MRVVU2O7FQQAF64VTRYA Jason

    Did not work. I got a syntax error. I did exactly as is here.

  • Asdf

    “Unarguably” you are an idiot.  Word 2010 is a huge step back for people that actually work with documents rather than play games.

  • kimmi

    Can’t you achieve the same result by going to Insert, Text from file (Object), and selecting the files you want to merge?

    • Alex Campbell

      When I have done that I am only able to combine 19 or 20 documents. I have one hundred two page documents I need to combine.

  • http://www.facebook.com/people/Jeff-Cole/100001056274475 Jeff Cole

    IF IT DOESN’T Work. It’s because the quotes around the path aren’t correct in the example.
    “C:UsersUsman JavaidDesktopWord documents” is what he has listed. But look at the FIRST double-quote! It’s a little different than what ou want. Just re-type it and you’re good to go. ““

  • Heather

    Just too too difficult

  • Guest

    What if I want to merge two documents that isn’t in the same folder? Is there any way to specify which documents that should be merged? Instead of just merging all .doc in a folder.

  • Johan Indrevåg

    How can I include top and bottom text from the original files in the concatenated file?

  • Zog

    Ridiculously over-complicated. Why is there not a simple, in-built way of doing this? It seems like it should surely be a basic function of Word? How have the software designers overlooked this?
    It’s much quicker and simpler to just copy-and-paste, neolithic as that is.

  • Dipesh

    this was ridiculously tricky. If you’re using Word 2010, then click on “Insert”, then off to the right you’ll see “Object” – click on that down arrow, choose “Text from File” and then choose the Word files you want to merge together. No VB coding required.

    • Emily

      Dipesh, I love you :-*

    • jake3_14

      That’s not a true merge; it’s just stuffing one file into another. What most people want is to collate comments from multiple reviewers into a single document and have the different author’s comments appear adjacent to each other.

  • Frankstar

    Why is it soooooooooooo complicated! Why isn’t it just as simple as combining two pdf documents? This is the most frustrating software ever invented.

    • http://www.facebook.com/geralyn.mulholand Geralyn Mulholand

      You don’t need to use the macro to merge your files unless they both have headers. If only one doc has a header, and the other is plain text, it can be done without too much trouble. With the header doc open, at the beginning of the document, insert a page break. Then, chose Insert —> Object —> Text from file… Choose the non-header doc and press ENTER to merge them. You might have to tweak the page breaks a little bit, but the pages all the pages should be intact, and exactly as the originals when you’re done. Hope this helped!

  • Leonardo

    Hi, im having a problem, i get this error “Compile error: Invalid or unqualified reference”. I know it is because of the spaces between ” * .docx”, but after i delete the spaces they apear again (after moving the cursor from the area), they wont disappear.
    Also, how do you Change Smart Quotations into Dumb Quotations??, may be this malfunction caused by this?

    Thank you

  • Cissy

    I got halfway through this and gave up. Way too complicated….who can remember all of that info?

  • tinespeen

    Wow some people are harsh :-/

    Question: would this work dynamically? I want a merge of say 2 documents whenever I print, for example I have a technical document used for many contexts so don’t wan’t to copy paste every time

  • Joe

    All this advice (as well as this article) is horrible. Simply select the documents in Explorer and drag and drop them into a new Word document. It will combine everything without issue.

  • Steve

    Guys, just dragging the documents from explorer wont let you edit the documents (but if that’s all you’re looking for, then that works) otherwise:

    1.Select the “Insert” tab.

    2.Locate “Object”, press a small triangle next to it, and click “Text from File” from the dropdown menu.

    3.After that, you can select files to be merged into the current document. By pressing and holding Ctrl to select more than one documents.

    (Note: Documents placed at the top will be merged in the first place, so please sort and number each target document in case that you want to keep a certain sequence for your documents. )

  • Adam

    Is it possible to take two documents and merge them page by page. What I’m trying to say is I want page 1 from document 1 then page 1 from document 2. Then page 2 from document 1 and page 2 from document 2 and so on.

  • Ruth

    So awesome! Worked like a dream
    Thank you

  • C

    I need to merge 2 documents into 1 document. The first document is in portrait mode with a header that needs to repeat on each page. The second document is in landscape mode with a header that needs to repeat from page 2 to the last page. Yes, pages 2 on will need to have 2 separate headers. Is this possible to do this in Word?

  • Merrilyn

    This is serviously way too complicated for a simple minded, non-technical person like me. Why can’t there just be a simple function with word to combine documents. Following this is likely to get me into serious difficulties.

  • corey

    Yes, I am trying this and it’s not working. My questions are as follows:
    In the Sub MergeDocs() is there supposed to be something added between the parentheses? Also, StrFile=Dir$(strFolder&”.docx”, is “strFolder” supposed to be the name of the folder or is it left “as is”? And Do Until strFile=”” is there supposed to be something between the quote marks? One last, in strFile=Dir$() is there supposed to be something inside these parentheses? Thanks so much.

  • ted

    Hi,

    I was working on this code. In the file I need to combine multiple word files from a dynamic location (means the location can changed as per the requirement).
    I got a static code, which is working. But i want to convert it to a dynamic code, where i can set the folder location using a folder picker.

    Please help.

    Private Sub Document_New()


    Dim rng As Range
    Dim MainDoc As Document
    Dim strFile As Variant
    Dim strFolder As FileDialog

    Set MainDoc = ActiveDocument
    Set strFolder = Application.FileDialog(msoFileDialogFolderPicker)
    strFolder.AllowMultiSelect = True
    strFolder.Show
    strFile = Dir$(STFolder & “” & “*.docx”)
    Do While strFile “”
    Set rng = MainDoc.Range
    rng.Collapse wdCollapseEnd
    rng.InsertBreak
    rng.InsertFile STFolder & strFile
    strFile = Dir$()
    Loop
    ActiveDocument.TablesOfContents(1).Update
    End Sub