The following code demonstrates the problem which is stated in questions title.
Copy & paste it in a new Microsoft Excel 2003 workbook.
Sub mytest()
mypath = Application.GetSaveAsFilename()
Workbooks.OpenText Filename:=mypath, DataType:=xlDelimited, _
TextQualifier:=xlTextQualifierDoubleQuote, _
semicolon:=True, _
fieldinfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2)), _
Local:=True
End Sub
Execute the code. It will ask for an input file where you should use this semicolon-seperated test.csv. It creates a new workbook and imports all the data from test.csv to sheet1.
The picture below shows the result
But It should have shown a result like this
fieldinfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2))
states that Excel should treat all imported data as text. Unfortunately it doesn't.
Can someone show me how to use opentext and fieldinfo in the correct way?
I already know the work-around with QueryTables.Add(Connection[...].
But thats not a solution for my case.
If you rename the extension from the input file from .csv to .txt the fieldinfo
parameter works as designed.