Hi all,
I built a macro to
1) Pop a dialog box for user to choose a txt file (csv with tab as delimiter)
2) Import the data accordingly to a new sheet.
But something is wrong and I am not sure what, I reckon it may be the bit .Name.
Any suggestions?
I built a macro to
1) Pop a dialog box for user to choose a txt file (csv with tab as delimiter)
2) Import the data accordingly to a new sheet.
But something is wrong and I am not sure what, I reckon it may be the bit .Name.
Any suggestions?
Code:
Sub import()
Dim vFileName
vFileName = Application.GetOpenFilename("Text Files, *.txt", , "Please select CSV file")
If vFileName = "False" Then Exit Sub
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" + vFileName, Destination:=Range("$A$1"))
.Name = vFileName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 950
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
Last edited by a moderator: