Something like this I suppose:
Option Explicit
Sub AppendFiles1()
Dim SourceNum As Long
Dim DestNum As Long
Dim Temp As String, fPath As String
Dim fDest As String, fName As String
fPath = "C:\2010\" 'do not forget the final \ in this string
fDest = "C:\2010\Imported\DEST.TXT" 'file to append to
' If an error occurs, close the files and end the macro.
On Error GoTo ErrHandler
' Open the destination text file.
DestNum = FreeFile()
Open fDest For Append As DestNum
' Open the source text files
SourceNum = FreeFile()
fName = Dir(fPath & "*.txt")
Do While Len(fName) > 0
Open fPath & fName For Input As SourceNum
' Include the following line if the first line of the source
' file is a header row that you do now want to append to the
' destination file:
' Line Input #SourceNum, Temp
' Read each line of the source file and append it to the
' destination file.
Do While Not EOF(SourceNum)
Line Input #SourceNum, Temp
Print #DestNum, Temp
Loop
Close #SourceNum
fName = Dir
Loop
CloseFiles:
' Close the destination file and the source file.
Close #DestNum
Exit Sub
ErrHandler:
MsgBox "Error # " & Err & ": " & Error(Err)
Resume CloseFiles
End Sub
This will open every text file in the C:\2010 folder and add it to the file C:\2010\Imported\DEST.TXT.
Bookmarks