|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
How to traverse folders and subfolders to merge a word document into one document?
How to traverse folders and subfolders to merge a word document into one document?
The folders and subfolders are word documents, and the contents of all word documents are merged into one word document. That is, the original content in each word is integrated into a word document in order |
#2
|
|||
|
|||
Code:
Sub MergeDocs() Dim rng As Range Dim MainDoc As Document Dim strFile As String, strFolder As String Dim Count As Long With Application.FileDialog(msoFileDialogFolderPicker) .Title = "Pick folder" .AllowMultiSelect = False If .Show Then strFolder = .SelectedItems(1) & Application.PathSeparator Else Exit Sub End If End With Set MainDoc = Documents.Add strFile = Dir$(strFolder & "*.doc") ' can change to .docx Count = 0 Do Until strFile = "" Count = Count + 1 Set rng = MainDoc.Range With rng .Collapse wdCollapseEnd If Count > 1 Then .InsertBreak wdSectionBreakNextPage .End = MainDoc.Range.End .Collapse wdCollapseEnd End If .InsertFile strFolder & strFile End With strFile = Dir$() Loop MsgBox ("Files are merged") lbl_Exit: Exit Sub End Sub |
#3
|
||||
|
||||
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
How come there is no response after the code runs?
|
#5
|
|||
|
|||
Quote:
|
#6
|
|||
|
|||
Quote:
|
#7
|
||||
|
||||
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
|
#9
|
||||
|
||||
Well, if you tried it, you would know that it works as described...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
Quote:
Can I add page numbers for each page after merging files? |
#11
|
|||
|
|||
Can I add page numbers for each page after merging files? The format of page numbers is the current page number and the total number of pages. For example, in the form of 8/800. 8 is the current page number, and 800 is the total number of pages after the merged document.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Searching through folders/ subfolders and rename files if certain condition is met | mihnea96 | Excel | 1 | 05-15-2017 07:09 AM |
Merge fields from Excel into word document | Tonykiwi | Word | 5 | 10-11-2015 12:54 PM |
Merge answers into one word document | RonNCmale | Word | 1 | 01-01-2014 12:28 PM |
Order of Folders in Document Library | eliz.bell | Word | 2 | 04-03-2012 11:49 AM |
Can't create subfolders in shared Contact folders | shellyrc7 | Outlook | 0 | 03-30-2012 08:18 PM |