473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How do I create an Excel workbook with multiple worksheets?

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????

Thanks in advance.

Regards,
Nov 20 '05 #1
5 8026
Hi Iris,

Paul Clement gave yesterday a very nice sample in this newsgroup.

http://www.google.com/gr************...******@4ax.com

I hope this helps,

Cor
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????
Thanks in advance.

Regards,

Nov 20 '05 #2
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)
Nov 20 '05 #3
Thanks Paul. I will try this.

Iris

"Paul Clement" wrote:
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)

Nov 20 '05 #4
On Tue, 29 Jun 2004 07:42:03 -0700, "Iris" <Ir**@discussions.microsoft.com> wrote:

¤ Hi Paul:
¤
¤ This code works using VB.net in Visual Studio 2003 only.
¤
¤ I have Visual Basic 6. Can I use this code in Visual Basic 6? If not, what additional components/references do I need? Thanks in advance.
¤

Yes, you would use ADO instead of ADO.NET under VB 6.0:

Function ImportTextToExcel() As Boolean

Dim cnn As New ADODB.Connection
Dim strSQL As String

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\Book20.xls;Extended Properties=Excel 8.0;"

strSQL = "SELECT * INTO [TextImportSheet] FROM [Text;DATABASE=e:\My
Documents\TextFiles].[TabDelimitedFile.txt]"

cnn.Execute strSQL
cnn.Close

End Function
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #5
raj
Hi Paul

COuld u please tell me how to do otherway arround (.xls to .txt)?

raj

"Paul Clement" wrote:
On Tue, 29 Jun 2004 07:42:03 -0700, "Iris" <Ir**@discussions.microsoft.com> wrote:

¤ Hi Paul:
¤
¤ This code works using VB.net in Visual Studio 2003 only.
¤
¤ I have Visual Basic 6. Can I use this code in Visual Basic 6? If not, what additional components/references do I need? Thanks in advance.
¤

Yes, you would use ADO instead of ADO.NET under VB 6.0:

Function ImportTextToExcel() As Boolean

Dim cnn As New ADODB.Connection
Dim strSQL As String

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\Book20.xls;Extended Properties=Excel 8.0;"

strSQL = "SELECT * INTO [TextImportSheet] FROM [Text;DATABASE=e:\My
Documents\TextFiles].[TabDelimitedFile.txt]"

cnn.Execute strSQL
cnn.Close

End Function
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
11
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it...
7
by: KC | last post by:
Does anybody know how to add a specific number of worksheets to an Excel spreadsheet through VB.net? I'm trying to export some datatables to an excel file, but I only want as many sheets in the...
3
by: James Wong | last post by:
Dear all, I have an old VB6 application which can create and access Excel object. The basic definition statements are as follows: Dim appExcel As Object Dim wkb1 As Excel.Workbook Dim wks1...
7
by: Alain \Mbuna\ | last post by:
Hi everybody. In my program I have some data that is calculated after some input from the user. I have written some code that opens an Excel workbook, with 5 worksheets and the calculated data...
4
by: paul.chae | last post by:
I have a table in Access with about 3000 records. There are ~60 unique values in the ID field for the 3000 records. What I would like to do is automatically generate multiple Excel worksheets...
2
by: madeleine | last post by:
I'm hoping the answer to this is that I'm just doing something silly, but I'm really scratching my head over this one. I'm importing data from multiple workbooks, each workbook has a sheet called...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.