Public Function basCSV2Array(FName As String, _
Optional RecSep As String = vbCrLf, _
Optional FldSep As String = ",") As Variant
Dim Fil As Integer
Dim NRecs As Long
Dim NFlds As Long
Dim Idx As Long
Dim J As Long 'indices
Dim RawFile As String 'Holds the entire contents of the file
Dim RawSplit() As String 'the file split up on a line per line basis
Dim OneLine() As String 'used to hold the tokens for one line
Dim RptAry() As String '2d array. Holds X lines & N elements per line
Fil = FreeFile 'get the next free file number
'This works for large files. I (Troy Williams)tried it
'with a 50 meg file on a computer with 128 Mb of ram and it worked fine.
'open the file and dump the contents into the rawfile variable
Open FName For Binary As #Fil 'Open file
RawFile = String$(LOF(Fil), 32) 'Create "empty" String of Length
Get #Fil, 1, RawFile 'Fill "Empty Str with File
Close #Fil 'Close File
'Get the Nunber of Records and Fields
RawSplit = Split(RawFile, RecSep) 'Split the file up by lines
NRecs = UBound(RawSplit) - 1 'Num Lines/Records in the file
OneLine = Split(RawSplit(0), FldSep) 'Split the first line
NFlds = UBound(OneLine) 'Get the Number of Fields
ReDim RptAry(0 To NRecs, 0 To NFlds)
For Idx = 0 To NRecs
OneLine = Split(RawSplit(Idx), FldSep)
For Jdx = 0 To NFlds
RptAry(Idx, Jdx) = OneLine(Jdx)
Next Jdx
Next Idx
basCSV2Array = RptAry
End Function