View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default import multiple files

great, many thanks

"Patrick Molloy" wrote:

Option Explicit

Sub GetData()

Dim rowindex As Long
Dim sFile As String
Dim source As String
Dim fso As Object
Dim oFile As Object
Dim txt As Object
Dim text

Set fso = CreateObject("Scripting.FileSystemObject")
source = "s:\"

For Each oFile In fso.GetFolder(source).Files

If UCase(Right(oFile.Name, 4)) = ".CSV" Then

Set txt = fso.OpenTextFile(source & "\" & oFile.Name)
With txt
Do Until .AtEndOfStream
text = .ReadLine
rowindex = rowindex + 1
If rowindex 65000 Then
MsgBox "TOO MANY LINES!!"
Exit Sub
End If
Cells(rowindex, 1) = text
Loop
.Close
End With
Set txt = Nothing
End If

Next

End Sub


"Dan" wrote:

I have some csv files. How many is not known and the amount of data on them
vary - but they all have trhe same format (same number of colums).

I will need to import all the data on those file one by one to an excel sheet.

Can that be done even though I dont know how many csv file are there in my
folder?

Many thanks.
Raphael