E
Eskimo
Good Day,
I have this routine i found in a search that combines many CSVs into one.
Public Sub PrependFileNameAndConcatenate( _
ByVal TheFolder As String, _
OutputFile As String, _
Optional FileSpec As String = "*.csv")
'Reads all files in TheFolder that match FileSpec.
'Concatenates them to OutputFile, prepending the filename
'to each line.
Dim lngIn As Long
Dim lngOut As Long
Dim strFN As String
Dim strLine As String
lngOut = FreeFile()
Open OutputFile For Output As #lngOut
'Make sure folder name ends with \
If Right(TheFolder, 1) <> "\" Then
TheFolder = TheFolder & "\"
End If
strFN = Dir(TheFolder & FileSpec)
Do While Len(strFN) > 0 'loop through all files
lngIn = FreeFile()
Debug.Print "Processing " & strFN
Open TheFolder & strFN For Input As #lngIn
'enclose file name in quotes
strFN = """" & strFN & ""","
Do Until EOF(lngIn) 'loop through lines in files
Line Input #lngIn, strLine
Print #lngOut, strFN & strLine
Loop
Close #lngIn
strFN = Dir() 'get next filename
Loop
Close #lngOut
End Sub
but in order to to run this bit of code, I am needing to call this routine
with a call in the Immediate Window with this..
Call PrependFileNameAndConcatenate("C:\myCSVFiles\", "C:\temp\combined.txt")
Is there any way that I can just add this call procedure and the constant
file locations into the code and simply run it, without having to use the
immediate window? That way I can run a macro or button on a form to run the
routine.
Thanks,
Eskimo
I have this routine i found in a search that combines many CSVs into one.
Public Sub PrependFileNameAndConcatenate( _
ByVal TheFolder As String, _
OutputFile As String, _
Optional FileSpec As String = "*.csv")
'Reads all files in TheFolder that match FileSpec.
'Concatenates them to OutputFile, prepending the filename
'to each line.
Dim lngIn As Long
Dim lngOut As Long
Dim strFN As String
Dim strLine As String
lngOut = FreeFile()
Open OutputFile For Output As #lngOut
'Make sure folder name ends with \
If Right(TheFolder, 1) <> "\" Then
TheFolder = TheFolder & "\"
End If
strFN = Dir(TheFolder & FileSpec)
Do While Len(strFN) > 0 'loop through all files
lngIn = FreeFile()
Debug.Print "Processing " & strFN
Open TheFolder & strFN For Input As #lngIn
'enclose file name in quotes
strFN = """" & strFN & ""","
Do Until EOF(lngIn) 'loop through lines in files
Line Input #lngIn, strLine
Print #lngOut, strFN & strLine
Loop
Close #lngIn
strFN = Dir() 'get next filename
Loop
Close #lngOut
End Sub
but in order to to run this bit of code, I am needing to call this routine
with a call in the Immediate Window with this..
Call PrependFileNameAndConcatenate("C:\myCSVFiles\", "C:\temp\combined.txt")
Is there any way that I can just add this call procedure and the constant
file locations into the code and simply run it, without having to use the
immediate window? That way I can run a macro or button on a form to run the
routine.
Thanks,
Eskimo