Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

VBA-Excel – Merger – Merge or Combine Many Word Documents Into One

Download Link:WordMerger

If you want to combine or merger many word document into one file and you don’t want to do it manually, This piece of software will allow you merge as many word document you want, say 500-1000 word documents. This tool will provide you to option to select ot de-select word documents before merging.

How to Use it:

  1. Down­load the WordMerger.xlsm from the link pro­vided at the top and at the bot­tom of this article.
  2. Place all the Word documents, which you want to com­bine, into one folder (make sure all files are closed).

Word Merger -1

Word Merger -1

3. Open the WordMerger.xlsm.

Word Merger -2

Word Merger -2

4. Put the “Folder path” Example : “ C:\Users\Sumit Jain\Desktop\Word Docs”
5. Put destination path for Merged Files : “ C:\Users\Sumit Jain\Desktop\”
6. Click on Fetch Files . This will fetch files from the Folder and will display.

Fetch Button

Fetch Button

Fetch Files

7. Select or de-select files.

Select Files

Select Files

8. Click on Merge

Merge Button

Merge Button

9. Files will be mergred and saved at the given location.

Merged File

Merged File

Complete Code:

    'Dim fso As New FileSystemObject

    Dim NoOfFiles As Double

    Dim counter As Integer

    Dim r_counter As Integer

    Dim s As String

    Dim listfiles As Files

    Dim newfile As Worksheet

    Dim mainworkbook As Workbook

    Dim FetchFileClicked

    Dim Folderpath As Variant
Sub Sumit()
    If FetchFileClicked = False Then
        MsgBox "First click the 'Fetch Files' button"
        End
    End If

    Application.ScreenUpdating = False
    strRandom = Replace(Replace(Replace(Now, ":", ""), "/", ""), " ", "")
    MergeFileName = "Merger" & strRandom & ".doc"
    MergeFolder = mainworkbook.Sheets("Main").Range("L10").Value

    Set objWord = CreateObject("Word.Application")

   Set objDoc = objWord.Documents.Add

   objWord.Visible = True

   Set objSelection = objWord.Selection
   objDoc.SaveAs (MergeFolder & MergeFileName)
    For i = 1 To NoOfFiles
        If Range("B" & i).Value = "Yes" Then
            Set objTempWord = CreateObject("Word.Application")
            Set tempDoc = objWord.Documents.Open(Folderpath & "\" & Range("A" & i).Value)
            Set objTempSelection = objTempWord.Selection
            tempDoc.Range.Select
            tempDoc.Range.Copy
            objSelection.TypeParagraph
            objSelection.Paste
            tempDoc.Close
        End If
    Next
    objDoc.Save
    Application.ScreenUpdating = True
    mainworkbook.Sheets("Main").Activate
    MsgBox "Completed...Merge File is saved at " & MergeFolder & MergeFileName
    FetchFileClicked = False
End Sub
Sub fetchFiles()
    Set mainworkbook = ActiveWorkbook
    Range("A:A").Clear

    Range("B:B").Clear
    Folderpath = mainworkbook.Sheets("Main").Range("L8").Value
    Set fso = CreateObject("Scripting.FileSystemObject")
    NoOfFiles = fso.GetFolder(Folderpath).Files.Count
    Set listfiles = fso.GetFolder(Folderpath).Files
    counter = 0
    For Each fls In listfiles
        counter = counter + 1
        Range("A" & counter).Value = fls.Name
        Range("B" & counter).Value = "Yes"
        Range("A" & counter).Borders.Value = 1
        Range("B" & counter).Borders.Value = 1
        With Range("B" & counter).Validation
             .Delete
            'replace "=A1:A6" with the range the data is in.
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
             Operator:=xlBetween, Formula1:="Yes,No"
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
        End With
    Next
     MsgBox "Files are Fetched,Please select the files to be merged"
     FetchFileClicked = True
End Sub

 

Download Link:WordMerger

 

You may also like...

21 Responses

  1. Nb says:

    Hi,

    Thanks for the above code, it is really good and exactly what i am looking for. One thing that I seem to have a problem with is to keep the source formatting and not the destination formatting. Is there a method to do that easily ?

    thanks
    Nb

  2. Olav Poulsen says:

    I copied the complete code into a new Excel VBA Macro, to use it for merging Word files created from the same Excel work book. Unfortunately the “Sumit” code will not run. I wonder if there is something missing or there might be an error in the code. The Macro stops claiming that “User-defined type not defined”. In VBA the line “Dim listfiles As Files” is marked. Would be great if you can send me a unprotected copy of the WordMerger file, so I can copy the code directly from your VBA code.

  3. pat says:

    I had the same formatting issue. I kept losing the formatting when copying and pasting. Use this in the For loop:

    objSelection.PasteAndFormat (wdPasteDefault):

  4. Rishi says:

    This is genius work! can you please email me the password to check the codes to [email protected]

  5. Hans says:

    hi Rishi, Could you please e-mail me the password? I would like to make it recursive and fix the formatting. thank you!

  6. Julien says:

    Hi,

    Can you send me the password ? [email protected] ?
    Thanks in advance.

  7. Rams says:

    Could you please e-mail me the pass­word? I would like to make it PDF format.

  8. kevin says:

    can you please send me the password? thanks [email protected]

  9. Olivier says:

    This is great work! can you please email me the pass­word to check the codes to [email protected]

  10. kevin says:

    Does anybody know:
    Is there a command to put in the macro to make the merge print each separate document starting on a separate page?

    The next document always seems to start on the very next line which often is near the bottom of the previous document. I just want each subsequent document that is merged to start printing on the next blank page.

  11. Chantal says:

    Hi SJ, Can you please send me the password as well? Thank you and greatly appreciate the excel sheet!
    [email protected]

  12. John Bucklew says:

    Can you please send me the password? Thanks, My email is [email protected]

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: