I'm trying to import data from multiple CSV files in a single folder.

I have an application that produces a changing number of CSV files with the same format, and I'm trying to create a macro to import them all to a single worksheet.

I'm a newbie to VBA so I've started by looking for examples from around the web. The current code I'm using (not mine) is included below. It's giving me a "Device Unavailable" error.

I'd be very grateful for any help!

Thank you,
Stuart



Sub ImportAllCSV()
Dim FName AsVariant, R AsLong
R
=1
FName
= Dir("*.csv")
DoWhile FName <>""
ImportCsvFile FName
, ActiveSheet.Cells(R,1)
R
= ActiveSheet.UsedRange.Rows.Count +1
FName
= Dir
Loop
EndSub

Sub ImportCsvFile(FileName AsVariant, Position As Range)
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;"& FileName _
, Destination:=Position)
.Name = Replace(FileName,".csv","")
.FieldNames =True
.RowNumbers =False
.FillAdjacentFormulas =False
.RefreshOnFileOpen =False
.BackgroundQuery =True
.RefreshStyle = xlInsertDeleteCells
.SavePassword =False
.SaveData =True
.AdjustColumnWidth =True
.TextFilePromptOnRefresh =False
.TextFilePlatform = xlMacintosh
.TextFileStartRow =1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter =False
.TextFileTabDelimiter =True
.TextFileSemicolonDelimiter =False
.TextFileCommaDelimiter =False
.TextFileSpaceDelimiter =False
.TextFileOtherDelimiter =","
.TextFileColumnDataTypes = Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
.Refresh BackgroundQuery:=False
EndWith
EndSub