I have the below line to import a csv format file.
Workbooks.OpenText Filename:=sPath, DataType:=xlDelimited, Comma:=True, FieldInfo:=Array(Array(18, 5), Array(19, 5)), Local:=True
From microsoft's documentation here, the FieldInfo doesn't have to be in any order if it is in delimited.
The column specifiers can be in any order. If there's no column specifier for a particular column in the input data, the column is parsed with the General setting.
However excel seems to treat the first array as 1st column and 2nd array as 2nd column no matter what I put in the first parameter Array(Array(x, 5), Array(y, 5))
. So to reach the 18th & 19th column, I have to do this, which isn't pretty:
Workbooks.OpenText Filename:=sPath, DataType:=xlDelimited, Comma:=True, _
FieldInfo:=Array(Array(1, 1), _
Array(2, 1), _
Array(3, 1), _
Array(4, 1), _
Array(5, 1), _
Array(6, 1), _
Array(7, 1), _
Array(8, 1), _
Array(9, 1), _
Array(10, 1), _
Array(11, 1), _
Array(12, 1), _
Array(13, 1), _
Array(14, 1), _
Array(15, 1), _
Array(16, 1), _
Array(17, 1), _
Array(18, 5), _
Array(19, 5)), _
Local:=True
csv file sample data:
fill_c1,pick_n2,po_num3,quanti4,addres5,cust_s6,color_7,size_d8,style9,shipto10,shipto11,addres12,addres13,city14,state15,zipcod16,custom17,start_18,end_da19,udford20
"52","1","2","000000001","000000000000000000000000000000","6","Z","XS","7","","","","","","","","M",20190310,20190318,"CF3"
"52","1","2","000000002","000000000000000000000000000000","6","Z","S","7","","","","","","","","M","20190310","20190318","CF3"