Link to home
Start Free TrialLog in
Avatar of Alex Campbell
Alex CampbellFlag for United States of America

asked on

Word 2010 Macro to Merge Files Not Working

This macro is to merge all the files in a folder into the current document BUT I would also like to be able to tell it a different folder OR even better to tell it to merge only selected files in a folder.  Number one goal is to get the merge working.

Sub MergeDocs()
Dim rng As Range
Dim MainDoc As Document
Dim strFile As String
Const strFolder = "U:\MergeDocs\"
Set MainDoc = Documents.Add
strFile = Dir$(strFolder&"*.docx")
Do Until strFile = ""
Set rng = MainDoc.Range
rng.Collapse wdCollapseEnd
rng.InsertFile strFolder & strFile
strFile = Dir$()
Loop
End Sub

Open in new window

Word-Macro-Merge-File.jpg
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial