473,836 Members | 1,996 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 8038
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
9251
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
4062
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
11589
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
10752
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
2435
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
8724
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
3508
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
6253
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
5404
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
9820
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
9670
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10844
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...
0
10254
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9374
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...
1
7792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6979
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
5826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3115
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.