ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   format columns as Text while using "Workbooks.OpenText" (https://www.excelbanter.com/excel-programming/410401-format-columns-text-while-using-workbooks-opentext.html)

BS[_2_]

format columns as Text while using "Workbooks.OpenText"
 
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



joel

format columns as Text while using "Workbooks.OpenText"
 
Array is row, column; you have column, Row
I would format columns before importing data.

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

"BS" wrote:

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




BS[_2_]

format columns as Text while using "Workbooks.OpenText"
 
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

"Joel" wrote in message
...
Array is row, column; you have column, Row
I would format columns before importing data.

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

"BS" wrote:

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







All times are GMT +1. The time now is 08:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com