View Single Post
 
Old 07-10-2021, 08:30 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,138
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

Use the filepicker instead (below) - or see Insert a selection of documents


Code:
Sub MergeDocs()
Dim rng As Range
Dim MainDoc As Document
Dim strFile As String
Dim Count As Long
    With Application.FileDialog(msoFileDialogFilePicker)
        .Title = "Pick files"
        .AllowMultiSelect = True
        If .Show <> -1 Then Exit Sub
        Set MainDoc = Documents.Add
        For Count = 1 To .SelectedItems.Count
            strFile = .SelectedItems(Count)
            Set rng = MainDoc.Range
            With rng
                .Collapse wdCollapseEnd
                If Count > 1 Then
                    .InsertBreak wdSectionBreakNextPage
                    .End = MainDoc.Range.End
                    .Collapse wdCollapseEnd
                End If
                .InsertFile strFile
            End With
        Next Count
    End With
    MsgBox ("Files are merged")
lbl_Exit:
    Exit Sub
End Sub
__________________
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