473,657 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8032
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**@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)
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**@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)

Nov 20 '05 #4
On Tue, 29 Jun 2004 07:42:03 -0700, "Iris" <Ir**@discussio ns.microsoft.co m> 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 ImportTextToExc el() As Boolean

Dim cnn As New ADODB.Connectio n
Dim strSQL As String

cnn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=e:\My Documents\Book2 0.xls;Extended Properties=Exce l 8.0;"

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

cnn.Execute strSQL
cnn.Close

End Function
Paul ~~~ pc******@amerit ech.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**@discussio ns.microsoft.co m> 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 ImportTextToExc el() As Boolean

Dim cnn As New ADODB.Connectio n
Dim strSQL As String

cnn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=e:\My Documents\Book2 0.xls;Extended Properties=Exce l 8.0;"

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

cnn.Execute strSQL
cnn.Close

End Function
Paul ~~~ pc******@amerit ech.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
9237
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 only exporting to single worksheet. but i need to export data to multiple worksheets. it is very urgent to us. so please help me in code.
11
4043
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 again, Excel hangs. OR if I open Excel again (say from a desktop icon) before I close Access, Excel hangs. (this has happened for both 97 & 2000 for me) I of course thought that I mustn't be unloading a variable properly.
7
11582
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 workbook as there are tables. Right now the routine I'm tweaking from http://support.microsoft.com/default.aspx?scid=kb;EN-US;306022 adds the default, (3).
3
10725
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 As Excel.Worksheet Set appExcel = New
7
2420
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 (no database!)with some titles and info, is entered in the worksheet in a printable format. This is some of the code... Public exlAppl As Excel.Application
4
8703
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 within a single workbook with these records. I would end up with around 500 worksheets, 1 for each unique ID value. I was thinking this could be done if I have an exported flag column in the table, and I search for the max (or min) on the ID...
2
3490
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 SubSAT and I need to get specific data from that into the database. I'm finding that if I have the workbook open on my desktop then the SubSAT % complete and the High level plan % come in fine, but as soon as the workbook is closed they come...
3
6241
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 that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" ...
3
5388
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 that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office"...
0
8394
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.