Workbooks.OpenText does not accept fieldinfo parameter

The following code demonstrates the problem indicated in the question header.

Copy and paste it into 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 

Run the code. It will request an input file where you should use this comma delimiter test.csv . It creates a new workbook and imports all the data from test.csv to sheet1.

The figure below shows the result.
enter image description here

But he had to show a result similar to this. enter image description here


fieldinfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2))
that Excel must process all imported data as text. Unfortunately, this is not so.

Can someone show me how to use opentext and fieldinfo correctly?

I already know a workaround with QueryTables.Add (Connection [...].
But this is not a solution for my business.

+4
source share
1 answer

If you rename the extension from the input file from .csv to .txt, the fieldinfo parameter works as configured.

+4
source

Source: https://habr.com/ru/post/1399688/


All Articles