'---------------------------------------------------------------------------------------
' Procedure : CombineFiles
' Purpose : Create a new file that combines the contents of the selected files.
'---------------------------------------------------------------------------------------
'
Public Sub CombineFiles(SourceFiles() As Variant, _
ByVal DestPath As String, _
ByVal DestFile As String)
Dim FSO As New FileSystemObject
Dim Tst_out As TextStream
Dim NewFile As String
Dim n As Integer
Dim Ans As Integer
NewFile = Replace(DestPath & "\" & Trim$(DestFile), "\\", "\")
Ans = vbYes
If FSO.FileExists(NewFile) Then
Ans = MsgBox("The file '" & NewFile & "' already exists." & vbCrLf & vbCrLf & _
"Do you want to replace it?", vbQuestion + vbYesNo, "Replace File?")
End If
If Ans = vbYes Then
Set Tst_out = FSO.CreateTextFile(NewFile)
For n = LBound(SourceFiles) To UBound(SourceFiles)
If Len(SourceFiles(n)) > 0 Then
If SourceFiles(n) = NewFile Then
MsgBox "Source and Destination cannot be the same file." & vbCrLf & _
"File '" & NewFile & "' bypassed.", vbExclamation, "Invalid Source"
Else
Tst_out.Write FSO.OpenTextFile(SourceFiles(n)).ReadAll
End If
End If
Next
Tst_out.Close
End If
Set Tst_out = Nothing
Set FSO = Nothing
End Sub