G
Guest
I'm trying to set up a script to import a CSV with every column formatted as
text to avoid loss of leading zeros that may be part of an actual barcode or
asset ID. The CSV file itself comprises of close to 100 columns. I would also
like to be able to ask the user for the file name and path as part of the
import.
I've tried several test scenarios using small CSV files and recording the
action, but I've been having trouble calling the file name.
Here is what I get when recording:
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\userID\Desktop\test.csv",
Destination:= _
Range("A1"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileCommaDelimiter = True
.TextFileColumnDataTypes = Array(2, 2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
I would like to be able to replace the "C:\Documents and
Settings\userID\Desktop\test.csv" with the user's selected file and path.
text to avoid loss of leading zeros that may be part of an actual barcode or
asset ID. The CSV file itself comprises of close to 100 columns. I would also
like to be able to ask the user for the file name and path as part of the
import.
I've tried several test scenarios using small CSV files and recording the
action, but I've been having trouble calling the file name.
Here is what I get when recording:
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\userID\Desktop\test.csv",
Destination:= _
Range("A1"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileCommaDelimiter = True
.TextFileColumnDataTypes = Array(2, 2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
I would like to be able to replace the "C:\Documents and
Settings\userID\Desktop\test.csv" with the user's selected file and path.