I can't figure this out - please help

P

PO

I'm using the following sub to import data from a textfile into excel.
Everything works fine except that all the columns in the textfile are merged
into one when inserted into Excel.

Text-file attributes:
=============
3 columns: Name, Address, Phone
TabDelimited
1st row contains rowheaders


Sub ImportData()
Dim cn As New ADODB.Connection

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\;" & _
"Extended Properties=""text;HDR=Yes;FMT=Delimited;"""

cn.Execute "SELECT * INTO [Newdata] IN 'C:\Data.xls' 'Excel 8.0;' FROM
Testdata.txt"

cn.Close

End Sub


1. How do I rewrite the code so the 3 columns in the text-file aren't merged
into column A in Excel?
2. Is it really necessary to use the schema.ini file or can it somehow be
avoided?



I also use a schema.ini file (in the same directory as the text-file):
============================================
[Testdata.txt]
ColNameHeader=True
Format=TabDelimited
MaxScanRows=0

TIA
PO
 
T

Tom Ogilvy

Why not just turn on the macro recorder, then open the file using the
file=>Open command and step through the Text import wizard, making the
appropriate choices. Then Turn off the macro recorder and look at the
recorded code. Alter to suit.
 

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

Top