VBA Workbooks.OpenText FieldInfo as a variable -> Import text into Excel question

antaeusguy

Board Regular
Joined
Mar 8, 2010
Messages
81
hi

I've several text file which I would want to import into Excel and each text file has different columns

I noted I could use Workbooks.OpenText and the property to change which columns to import and it's import format is FieldInfo.

I declared a variable called arrtext and this will change from file to file. I intended to use arrtext as the FieldInfo.

I tried the code below but is does not work.

Does anyone knows how to declare the variable for FieldInfo in .OpenText? Thanks a lot!


Code:
Sub TextImportTest()

Dim arrtext As String


    arrtext = "Array(Array(1, 1), Array(2, 2), Array(3, 9))"




    Workbooks.OpenText Filename:="C:\Users\john.doe\Desktop\test\test.txt", _
        Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
        xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
        Comma:=False, Space:=False, Other:=False, FieldInfo:=arrtext, TrailingMinusNumbers:=True


End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Dim arrtext()
arrtext = Array(Array(1, 1), Array(2, 2), Array(3, 9))

with FieldInfo you can not select columns to import, but columns to analyze
 
Upvote 0
As above ^ (Patel has correctly shown the syntax)
with FieldInfo you can not select columns to import, but columns to analyze

Just to clarify that the 2nd element of each array refers to xlColumnDataType constant; one of which is xlSkipColumn, or #9...
 
Upvote 0
I think I lost the plot on this one. So #9 column is still included in the open file, only it is not parsed... At least that what appears to happen. So if you don't want any particular column one has to either delete it or change to an import method instead.
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,716
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top