I actually prefer writing my own routines to import csvs into Excel. I find that they are a lot easier to customize (i.e. skipping columns or adding calculated data). Here's an example that creates a new workbook from a passed filename and application instance. It returns a reference to the sheet (handy for formatting in the calling function).
But the main question is why you need to go through Excel before putting the data into DBaseIII? Do you actually need to have a copy of it in Excel or were you just planning of using Excel to export to DBase? If not, I'd just use ADO and skip the Excel part.VB Code:
Private Function CSVToExcel(oApp As Excel.Application, sFile As String) As Excel.Worksheet Dim oBook As Excel.Workbook, lRow As Long, lCol As Long, sBuffer As String, iFile As Integer Dim sLines() As String, sRow() As String iFile = FreeFile Open sFile For Binary As #iFile sBuffer = String$(LOF(iFile), Chr$(0)) Get #iFile, , sBuffer Close #iFile sLines = Split(sBuffer, vbCrLf) Set oBook = oApp.Workbooks.Add Set CSVToExcel = oBook.Worksheets(1) With CSVToExcel For lRow = 0 To UBound(sLines) sRow = Split(sLines(lRow), ",") For lCol = 0 To UBound(sRow) .Cells(lRow + 1, lCol + 1).Value = sRow(lCol) Next lCol Next lRow End With End Function




Reply With Quote