ExcelChick
New Member
- Joined
- Jun 25, 2002
- Messages
- 6
I want to import some, but not all, columns from a *.csv file. I am trying to do this with VBA because I then have to do a bunch of other things with the data (replace values, rearrange the columns, etc.) and I want to do it all with one button.
My code works just fine if the file is named *.txt. But if I try this on the same file named *.csv ALL the columns import. Also, I need to import some "number" columns as text. Again, works fine on the *.txt, but not the *.csv.
Can anyone offer some insight on how to get this to work. (a solution other than renaming the file first
)
Thank you
ps. the file I importing is 48 columns, I only show few above to make it easier to read.
My code works just fine if the file is named *.txt. But if I try this on the same file named *.csv ALL the columns import. Also, I need to import some "number" columns as text. Again, works fine on the *.txt, but not the *.csv.
Can anyone offer some insight on how to get this to work. (a solution other than renaming the file first
Thank you
Code:
file = Application.GetOpenFilename()
Workbooks.OpenText Filename:=file, Origin:=437, StartRow:=1 _
, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=True _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 9), Array(2, 9), _
Array(3, 9), Array(4, 1), Array(5, 1), Array(6, 2), Array(7, 2), Array(8, 9), Array(9, 1), _
Array(10, 1)), TrailingMinusNumbers:=True
ps. the file I importing is 48 columns, I only show few above to make it easier to read.