On Tue, 22 Jun 2004 18:57:01 -0700, "Iris" <Ir**@discussio ns.microsoft.co m> 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:
[TabDelimitedFil e.txt]
ColNameHeader=F alse
Format=TabDelim ited
CharacterSet=AN SI
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 ImportTextToExc el() As Boolean
Dim ExcelConnection As New
System.Data.Ole Db.OleDbConnect ion("Provider=M icrosoft.Jet.OL EDB.4.0;" & _
"Data Source=e:\My Documents\Book2 0.xls;Extended Properties=Exce l 8.0;")
ExcelConnection .Open()
Dim ImportCommand As New System.Data.Ole Db.OleDbCommand ("SELECT * INTO [TextImportSheet]
FROM [Text;DATABASE=e :\My Documents\TextF iles].[TabDelimitedFil e.txt]", ExcelConnection )
ImportCommand.E xecuteNonQuery( )
ExcelConnection .Close()
End Function
Paul ~~~
pc******@amerit ech.net
Microsoft MVP (Visual Basic)