Hi,
When I normally manually import a CSV file, I tend to convert it to xlsx first and then import, because I get no import errors this way. Now I'm trying to do this dynamically, and it works syntactically, but I want it to skip 12 lines and my delimiter is semicolon.. These two factors are not working properly. Maybe you can help me.. Here is my code:
Private Sub CSV_2_XLS_And_Import(strPath As String, strCase)
Dim strNewPath As String
strNewPath = Left(strPath, InStrRev(strPath, ".") - 1) & ".xlsx"
CreateExcel strPath, strNewPath
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, strCase, strNewPath
Kill strNewPath
End Sub
Private Sub CreateExcel(strCSVPath As String, strXLSXSpath As String)
Dim wb As Object
With CreateObject("Excel.Application") 'False visibility is default
.Workbooks.OpenText FileName:=strCSVPath, startRow:=13, dataType:=1, Semicolon:=True
Set wb = .ActiveWorkbook
wb.saveas FileName:=strXLSXSpath, FileFormat:=51 '(xlWorkbookDefault, xlOpenXMLWorkbook)
wb.Close False
.Quit
End With
End Sub
When I normally manually import a CSV file, I tend to convert it to xlsx first and then import, because I get no import errors this way. Now I'm trying to do this dynamically, and it works syntactically, but I want it to skip 12 lines and my delimiter is semicolon.. These two factors are not working properly. Maybe you can help me.. Here is my code:
Private Sub CSV_2_XLS_And_Import(strPath As String, strCase)
Dim strNewPath As String
strNewPath = Left(strPath, InStrRev(strPath, ".") - 1) & ".xlsx"
CreateExcel strPath, strNewPath
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, strCase, strNewPath
Kill strNewPath
End Sub
Private Sub CreateExcel(strCSVPath As String, strXLSXSpath As String)
Dim wb As Object
With CreateObject("Excel.Application") 'False visibility is default
.Workbooks.OpenText FileName:=strCSVPath, startRow:=13, dataType:=1, Semicolon:=True
Set wb = .ActiveWorkbook
wb.saveas FileName:=strXLSXSpath, FileFormat:=51 '(xlWorkbookDefault, xlOpenXMLWorkbook)
wb.Close False
.Quit
End With
End Sub