See it in Action!Watch this video to see this macro in action.
The CodeHere is the code for this macro. Make sure the following References are setup before running it: Visual Basic For Applications, Microsoft Word 16.0 Object Library
'Leverage & Lean "Less Clicks, More Results" Sub CopyMultipleDocumentsintoOne() ' Means variable is in use Dim FolderPath As String ' Dim MasterDoc As String ' Dim oFile As Object ' Dim oFolder As Object ' Dim oFSO As Object ' Dim SeparateDoc As String ' On Error GoTo LeverageLean MasterDoc = ActiveDocument.Name 'Selection.HomeKey wdStory 'Move to Start of the Master Document Selection.EndKey wdStory 'Move to End of the Master Document FolderPath = Left(ActiveDocument.FullName, Len(ActiveDocument.FullName) - Len(ActiveDocument.Name)) 'Active Document File Path Set oFSO = CreateObject("Scripting.FileSystemObject") Set oFolder = oFSO.GetFolder(FolderPath) For Each oFile In oFolder.Files 'Loop through every File in FolderPath If InStr(1, oFile.Type, "Microsoft Word") <> 0 And oFile.Name <> MasterDoc And InStr(1, oFile.Name, "~") = 0 Then 'If the File Type contains the phrase Microsoft Word and is NOT Active Document and is NOT Lock File Application.ScreenUpdating = False 'Hide Screen Updates Application.DisplayAlerts = False 'Hide Display Alerts Application.Documents.Open FolderPath & "\" & oFile.Name, Visible:=False Documents(oFile.Name).Activate 'Open Separate Document SeparateDoc = ActiveDocument.Name Selection.WholeStory 'Select whole document Selection.Expand wdParagraph 'Expands your selection to current paragraph Selection.Copy 'Copy the content in the Separate Document Documents(oFile.Name).Close 'Close Separate Document Documents(MasterDoc).Activate 'Activate Master Document Selection.InsertAfter ("***Content from " & Left(oFile.Name, InStr(1, oFile.Name, ".") - 1) & ":" & vbNewLine) 'Source of the content Selection.Collapse Direction:=wdCollapseEnd Selection.PasteAndFormat wdPasteDefault 'Paste Separate Document Content into Master End If Next oFile MsgBox "Multiple Word Documents have been copied into this one!" Set oFSO = Nothing Set oFolder = Nothing Set oFile = Nothing Exit Sub LeverageLean: MsgBox (Err.Number & " - " & Err.Description & vbNewLine & vbNewLine & "Don't hesitate to email me: email@example.com") End Sub 'Stay Awesome
Macro MondayHere is the Macro Monday video this macro was featured in. Watch this video to learn how to get the most out of this macro and start using it today!
CustomizationThese lines of code can be customized to personalize this macro.
15. ‘Selection.HomeKey wdStory ‘Move to Start of the Master Document If you want the copied content to be pasted to the Beginning of the Master Document remove the comment in code line 15 and make code line 16 a comment
16. Selection.EndKey wdStory ‘Move to End of the Master Document By Default the copied content will be pasted to the End of the Master Document
18. FolderPath = Left(ActiveDocument.FullName, Len(ActiveDocument.FullName) – Len(ActiveDocument.Name)) ‘Active Document File Path By Default the Folder Path is the Active Word Document but you can change this to a different path if desired
35. Selection.InsertAfter (“***Content from ” & Left(oFile.Name, InStr(1, oFile.Name, “.”) – 1) & “:” & vbNewLine) ‘Source of the content Remove or make this code line a comment to NOT get the indication of where the content was copied from
41. MsgBox “Multiple Word Documents have been copied into this one!” Remove the MsgBox or make it comment to not see it once the macro finishes