Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default copy Excel worksheets into one text file

Hi
I want to create a job for copying all data from one
excel file containing many worksheets into only one text
file.

I have been experimenting with using Import Wizard in SQL
Server to create a Transform Data Task in DTS. This is
working, but my problem is that the Excel file contains
several worksheets. I want to repeat the procedure for
each worksheet, but I do not want one text file for each
worksheet. I want one text file containing data from all
the worksheets. The problem is that my text file is
emptied each time I execute the job, so I am not able to
add data to the existing text file. There are about
20000 rows in each worksheet, so I do not want to end up
using a solution that gives slow performance.

I have an alternative solution using Excel macros, and
this contains:

Open TextFile For Output As 1
Print #1
Loop

This will print one by one row to the text file.
I think I can make this work, but my question is:
Is there a better way to do this in Excel macros, in
command prompt, VBS, DTS?

Best regards
Helge Arntsen
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default copy Excel worksheets into one text file

One alternative would be to get all the data on one sheet - however, if
there are more than 3+ worksheets, then you would run out of room.

Another would be to write one textfile for each sheet, then combine them

in DOS/command window or using the shell command

copy a.txt+b.txt+c.txt d.txt

or copy *.txt d.txt

--
Regards,
Tom Ogilvy

"Helge Arntsen" wrote in message
...
Hi
I want to create a job for copying all data from one
excel file containing many worksheets into only one text
file.

I have been experimenting with using Import Wizard in SQL
Server to create a Transform Data Task in DTS. This is
working, but my problem is that the Excel file contains
several worksheets. I want to repeat the procedure for
each worksheet, but I do not want one text file for each
worksheet. I want one text file containing data from all
the worksheets. The problem is that my text file is
emptied each time I execute the job, so I am not able to
add data to the existing text file. There are about
20000 rows in each worksheet, so I do not want to end up
using a solution that gives slow performance.

I have an alternative solution using Excel macros, and
this contains:

Open TextFile For Output As 1
Print #1
Loop

This will print one by one row to the text file.
I think I can make this work, but my question is:
Is there a better way to do this in Excel macros, in
command prompt, VBS, DTS?

Best regards
Helge Arntsen



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default copy Excel worksheets into one text file

Hi Helga,

This is an adaptation (for each sheet) of something I posted a while ago:

Sub Range2TxtWB()
Dim MyData As DataObject, ws As Worksheet

Set MyData = New DataObject

Open "C:\Temp\Range2Txt_Test2.txt" For Output As #1

For Each ws In ActiveWorkbook.Worksheets
ws.UsedRange.Copy
MyData.GetFromClipboard
Print #1, "Start of " & ws.Name 'optional
Print #1, MyData.GetText(1)
Application.CutCopyMode = False
Next

Close #1

End Sub

You will need to set a reference (tools references) to "Microsoft
Forms 2.0 Library" unless already set by default.

Dave Peterson mentioned in a follow-up that he had a problem if he had a
"pretty large usedrange". It's worked fine and fast for me with a lot of
data. If it works for you it might be worth including a count of rows
copied and comparing with the rows of data in the final text file, also
some error handling.

Regards,
Sandy


Helge Arntsen wrote:
Hi
I want to create a job for copying all data from one
excel file containing many worksheets into only one text
file.

I have been experimenting with using Import Wizard in SQL
Server to create a Transform Data Task in DTS. This is
working, but my problem is that the Excel file contains
several worksheets. I want to repeat the procedure for
each worksheet, but I do not want one text file for each
worksheet. I want one text file containing data from all
the worksheets. The problem is that my text file is
emptied each time I execute the job, so I am not able to
add data to the existing text file. There are about
20000 rows in each worksheet, so I do not want to end up
using a solution that gives slow performance.

I have an alternative solution using Excel macros, and
this contains:

Open TextFile For Output As 1
Print #1
Loop

This will print one by one row to the text file.
I think I can make this work, but my question is:
Is there a better way to do this in Excel macros, in
command prompt, VBS, DTS?

Best regards
Helge Arntsen

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default copy Excel worksheets into one text file

"Helge Arntsen" wrote ...

I want to create a job for copying all data from one
excel file containing many worksheets into only one text
file.

I have been experimenting with using Import Wizard in SQL
Server to create a Transform Data Task in DTS. This is
working, but my problem is that the Excel file contains
several worksheets. I want to repeat the procedure for
each worksheet, but I do not want one text file for each
worksheet. I want one text file containing data from all
the worksheets.


The OLEDB provider for Jet 4.0 may be used to query/create both Excel
and text data sources. Therefore, you could do something like this in
T-SQL:

INSERT INTO
OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0','Data
Source=C:\Tempo\;Extended Properties=Text')...[db#txt]
(MyDateTimeCol, MyIntCol, MyTextCol)
SELECT
MyDateTimeCol, MyIntCol, MyTextCol
FROM
OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0','Data
Source=C:\Tempo\db.xls;Extended Properties=Excel 8.0')...[Sheet1$]
;

(BTW the '...' is a literal string of three periods, not an ellipsis.)

If you wanted to do it all in one hit, you could extend the inserted
dataset (and eliminate duplicates) by appending some SELECT clauses
using the UNION keyword.

Jamie.

--
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How keep links when copy worksheets to another file? Jack B Excel Discussion (Misc queries) 2 January 19th 09 01:45 AM
Import text file into Excel 2007 then copy sheet to another workbo DonnaO Excel Discussion (Misc queries) 2 October 9th 07 07:09 PM
How do I copy text using a formula between worksheets in Excel? Guero Excel Worksheet Functions 2 March 23rd 06 06:31 PM
How do I copy a Word text file into Excel in a way that each char. Newtech programmer Excel Discussion (Misc queries) 2 April 15th 05 07:07 PM
Copy worksheets into new file rglasunow[_17_] Excel Programming 7 March 5th 04 09:46 PM


All times are GMT +1. The time now is 04:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"