In a previous question I asked about a method for importing .csv files using Excel using VBA. I received a helpful answer about opening .csv files using VBA, but I worry that using this method will cause issues with date formats, as a commenter on another of my questions mentioned. With that in mind, is there a similar method to the one used by Dan to import files? I understand that recorded macros are often clumsy and so I was wondering how something like the standard code below would be improved.
With ActiveSheet.QueryTables.Add(Connection:= _
"FAKENAME.csv" _
, Destination:=Range("$A$1"))
.CommandType = 0
.Name = "FAKENAME"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 65001
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
UPDATE:
The issue that occurs with the dates if I choose not to import is like so:
DateTime Format
05/11/2014 3:22 Custom
4/27/2014 9:53:01 AM General
11/22/2013 8:29:35 AM Custom
05/11/2014 8:26 Custom
1/17/2014 12:28:24 PM General
05/11/2014 3:22 Custom
While this can be resolved when I import, if I simply open the file attempting to change the date format manually for the whole column doesn't actually change the format.