Hello Dear community,
I use following code to merge all Word documents in specific folder. "Generate"
All file names in specified folder are named as: Part1,Part2,Part3...
But it is merging with wrong order as : Part1,Part10,Part11 etc..
Can anyone help me to make it merge all with correct order please?
Thanks in advance,
I use following code to merge all Word documents in specific folder. "Generate"
All file names in specified folder are named as: Part1,Part2,Part3...
But it is merging with wrong order as : Part1,Part10,Part11 etc..
Can anyone help me to make it merge all with correct order please?
Thanks in advance,
VBA Code:
Sub merge()
Dim dlgFile As FileDialog
Dim objDoc As Document, objNewDoc As Document
Dim StrFolder, strFile As String
Set dlgFile = Application.FileDialog(msoFileDialogFolderPicker)
myPath = ThisDocument.Path & "\Generate\"
strFile = Dir(myPath & "*.docx", vbNormal)
Set objNewDoc = Documents.Add
While strFile <> ""
Set objDoc = Documents.Open(FileName:=myPath & strFile)
objDoc.Range.Copy
objNewDoc.Activate
With Selection
.Paste
'.InsertBreak Type:=wdPageBreak
.Collapse wdCollapseEnd
End With
objDoc.Close SaveChanges:=wdDoNotSaveChanges
strFile = Dir()
Wend
objNewDoc.Activate
Selection.EndKey Unit:=wdStory
Selection.Delete
objNewDoc.SaveAs myPath2
End Sub