After some testing, this is the combination of previous format and import format that worked for an english installation of Office. The installation of Office wasn't the culprit, it was the Regional settings of Windows. If the system's date has the MDY format, this code will work:
Format the column first, leave the import format as general, which is the default format, so I don't need to specify it.
And this for other languages And if the system's date has DMY or YMD format, then this code should be used:
Format the column first and then import with format by specifying it
Code:
Sub testEng()
Dim xlapp As Object
Dim ws As Object
'Start Excel
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = True
' Open the file
Set ws = xlapp.Workbooks.Add.worksheets(1)
ws.Columns(2).numberformat = "dd/mm/yyyy;@"
With ws.querytables.Add("Text;" & CurrentProject.Path & "\Transaction Report.csv", ws.range("A1"))
.TextFileStartRow = 9
.TextFileCommaDelimiter = True
.Refresh False
End With
End Sub
Format the column first, leave the import format as general, which is the default format, so I don't need to specify it.
Code:
Sub testOtherLang()
Dim xlapp As Object
Dim ws As Object
'Start Excel
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = True
' Open the file
Set ws = xlapp.Workbooks.Add.worksheets(1)
ws.Columns(2).numberformat = "dd/mm/yyyy;@"
With ws.querytables.Add("Text;" & CurrentProject.Path & "\Transaction Report.csv", ws.range("A1"))
.TextFileStartRow = 9
.TextFileCommaDelimiter = True
.TextFileColumnDataTypes = Array(1, 3, 1, 1, 1, 1, 1) '<-- second column format is 3
.Refresh False
End With
End Sub
Format the column first and then import with format by specifying it
Last edited: