you can try this
(with including Microsoft Excel x.x Object Library)
VB Code:
Sub MakeXL(csvPath As String, NewXLPath As String, NewXLSheetName As String, Delimiter As String) Dim wb As Workbook, ws As Worksheet Set wb = Workbooks.Add: Set ws = wb.Worksheets.Add ws.Name = NewXLSheetName ff = FreeFile Open csvPath For Input As ff On Error Resume Next Do While Not EOF(ff) Line Input #ff, buff n = n + 1 buff = Split(buff, Delimiter) If IsArray(buff) Then For c = 0 To UBound(buff) ws.Range(Chr(c + 65) & n) = buff(c) If Err Then 'if the first char of the item is -,+,= or etc. an error occures ws.Range(Chr(c + 65) & n) = "'" & buff(c) 'so we add a ' sign to the first char End If Next c Else ws.Range(Chr("A" & n)) = buff End If If Err Then MsgBox "Error on col:" & c + 1 & " row:" & n & vbCrLf & Err.Description Err.Number = 0 Loop Close #ff wb.Close True, NewXLPath End Sub
i tried the code and it ok![]()




Reply With Quote