Set wb = Workbooks.Open(sFilename)
Doesn't this just fill a sheet up to the maximum rows (65536 for Excel 2003), and ignore anything over that?
I would look at using ADO and treating the csv file as a database.
The code below reports the number of records. Remember to set a reference to Microsoft ActiveX Data Objects Library (Tools>References...)
Sub ADOReadCSVFile()
Const CSV_FILE As String = "TESTFILE.txt"
Dim strPathtoTextFile As String
'set reference to Microsoft ActiveX Data Objects Library (Tools>References...)
Dim objConnection As ADODB.Connection
Dim objRecordset As ADODB.Recordset
Set objConnection = New ADODB.Connection
Set objRecordset = New ADODB.Recordset
strPathtoTextFile = ThisWorkbook.Path & "\"
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=No;FMT=CSVDelimited"""
objRecordset.Open "SELECT * FROM " & CSV_FILE, objConnection, adOpenStatic, adLockOptimistic, adCmdText
If Not objRecordset.EOF Then MsgBox objRecordset.RecordCount
objRecordset.Close 'Close ADO objects
objConnection.Close
Set objRecordset = Nothing
Set objConnection = Nothing
End Sub
Notice how the path to the csv file is specified in the connection string and the name of the csv file itself is part of the SQL statement.
You can do a lot more than this with ADO, e.g filtering records "SELECT * FROM CSV_FILE WHERE Length = '0'" and other queries on the data.
CopyFromRecordset can handle copying recordsets on to multiple sheets.