On Tue, 22 Jun 2004 18:57:01 -0700, "Iris" <Ir**@discussions.microsoft.com> wrote:
¤ I have 8 text files (tab delimited) that I would like to import into an Excel workbook as 8 individual worksheets but I cannot find any example code on this subject. Can anyone help me please????
¤
If you use data access methods, tab delimited files require a schema.ini file similar to the
following:
[TabDelimitedFile.txt]
ColNameHeader=False
Format=TabDelimited
CharacterSet=ANSI
An entry would be required for each file to be imported. The file would be placed in the same
location as the text files.
If you are importing into an Excel Workbook and the Worksheets are to be created from the Import
then the following should work:
Function ImportTextToExcel() As Boolean
Dim ExcelConnection As New
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\Book20.xls;Extended Properties=Excel 8.0;")
ExcelConnection.Open()
Dim ImportCommand As New System.Data.OleDb.OleDbCommand("SELECT * INTO [TextImportSheet]
FROM [Text;DATABASE=e:\My Documents\TextFiles].[TabDelimitedFile.txt]", ExcelConnection)
ImportCommand.ExecuteNonQuery()
ExcelConnection.Close()
End Function
Paul ~~~
pc******@ameritech.net
Microsoft MVP (Visual Basic)