format columns as Text while using "Workbooks.OpenText"

  • Thread starter Thread starter BS
  • Start date Start date
B

BS

Hi,

I am writing code to import text files and set column formats in Office XP.

I tried (goal is to set column 1 and 6 to Text Format):

Workbooks.OpenText Filename:=.FoundFiles(i), startrow:=2,
DataType:=xlDelimited, _
Tab:=True, FieldInfo:=Array(Array(1, 2), Array(6, 2))

With this, Column 1 and 2 become Text instead of 1 and 6. I want to format
the columns properly before I bring any data in - so formatting after the
import is too late for my data.

What am I doing wrong?

Thanks,
Brij
 
Array is row, column; you have column, Row
I would format columns before importing data.

Columns("B:B").NumberFormat = "@"
Columns("F:F").NumberFormat = "@"
 
Joel,

The ref manual tells me that this Array format is (Column you want to
format, constant that represents format choice).

Text is xlTextFormat which has a value of 2. So I thought this Array(6, 2)
should have worked.

Thx for responding,

Brij
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top