'''
''' Open a CSV as text file to avoid formatting the data
'''
Sub CSV_Open_Text(fname As String)
'
Dim QueryConnection As String
Dim QueryName As String
Dim ColCnt As Long, I As Long
Dim QT As QueryTable
Dim WS As Worksheet
Dim FormatArray() As Long
Dim WB As Workbook
QueryConnection = "TEXT;" & fname
QueryName = "CSV_Import"
Set WB = Application.Workbooks.Add(xlWBATWorksheet)
WB.Activate
Set WS = ActiveSheet
With WS.QueryTables.Add(Connection:=QueryConnection, Destination:=Range("A1"))
.Name = QueryName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
.Refresh BackgroundQuery:=False
End With
Set QT = WS.QueryTables(QueryName)
ColCnt = ActiveSheet.UsedRange.Columns.count
If ColCnt > 20 Then
ReDim FormatArray(ColCnt - 1)
For I = 0 To ColCnt - 1
FormatArray(I) = 2
Next I
QT.TextFileColumnDataTypes = FormatArray
QT.Refresh
End If
End Sub