View Single Post
 
Old 08-04-2015, 01:42 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Rather than copy and paste which is slow and gobbles memory, use InsertFile e.g. as follows. The DoEvents command should prevent it appearing to hang.
Note that combining documents works best when all are based on the same template (including and especially the basedoc).

Code:
Sub CombineAll(sPath As String)
Dim baseDoc As Document, sFile As String
Dim oRng As Range
    On Error GoTo err_Handler
    Set baseDoc = Application.Documents.Add
    sFile = Dir(sPath & "*.doc")
    'Loop through all .doc files in that path
    Do While sFile <> ""
        Set oRng = baseDoc.Range
        oRng.Collapse wdCollapseEnd
        oRng.InsertFile sPath & sFile
        Set oRng = baseDoc.Range
        oRng.Collapse wdCollapseEnd
        oRng.InsertBreak Type:=wdSectionBreakNextPage
        sFile = Dir
        DoEvents
    Loop
    MsgBox "Process complete"
lbl_Exit:
    Set baseDoc = Nothing
    Set oRng = Nothing
    Exit Sub
err_Handler:
    MsgBox Err.Number & vbCr & Err.Description
    Err.Clear
    GoTo lbl_Exit
End Sub
A document of 3000+ pages will be slow to process, but is well within Word's capabilities. Hopefully the documents do not contain illustrations as this will make the document even more ponderous.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote