Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Export multiple Excel sheets to a single text file

I want to export (SaveAs) multiple worksheets to a single text file. probably
csv. By Microsoft's design I can't do that with a straight Save As from the
menu. So I thought maybe I could create a macro that would save each sheet
one at a time. Unfortunately this doesn't seem to work because
Workbook.SaveAs doesn't seem to have an append capability. Worse case is I
save each sheet to a separate file and manually append them. Short of that,
any programmatic suggestions?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Export multiple Excel sheets to a single text file


Hello,

Here are two lots of code one will put alll the sheest into sererate
txt on the c:/ drive.

the other will make a temp drive and split out all the sheets into .txt
files and then combine these into one .txt file C:\Output.txt
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Export multiple Excel sheets to a single text file

Hi Mainframer

For workbooks see
http://www.rondebruin.nl/mergetotxt.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Mainframer" wrote in message ...
I want to export (SaveAs) multiple worksheets to a single text file. probably
csv. By Microsoft's design I can't do that with a straight Save As from the
menu. So I thought maybe I could create a macro that would save each sheet
one at a time. Unfortunately this doesn't seem to work because
Workbook.SaveAs doesn't seem to have an append capability. Worse case is I
save each sheet to a separate file and manually append them. Short of that,
any programmatic suggestions?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Export multiple Excel sheets to a single text file

I'll have to look at this in depth and see how applicable it is to my
question. But for now, on the surface, it looks different. You are talking
about merging multiple workbooks into a text file and I am talking about
merging multiple worksheets to a text file.

Thanks for the reply.

"Ron de Bruin" wrote:

Hi Mainframer

For workbooks see
http://www.rondebruin.nl/mergetotxt.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Mainframer" wrote in message ...
I want to export (SaveAs) multiple worksheets to a single text file. probably
csv. By Microsoft's design I can't do that with a straight Save As from the
menu. So I thought maybe I could create a macro that would save each sheet
one at a time. Unfortunately this doesn't seem to work because
Workbook.SaveAs doesn't seem to have an append capability. Worse case is I
save each sheet to a separate file and manually append them. Short of that,
any programmatic suggestions?

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Export multiple Excel sheets to a single text file

Did I miss something here? I don't see any code.

"D_Rennie" wrote:


Hello,

Here are two lots of code one will put alll the sheest into sererate
.txt on the c:/ drive.

the other will make a temp drive and split out all the sheets into .txt
files and then combine these into one .txt file C:\Output.txt
.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Export multiple Excel sheets to a single text file


The way i posted the code, The NG feed wont support php tags from the
looks of things.

Option Explicit

Sub SaveSheetAsTXT()
'Save Each Sheet As Seperate File
Dim WS As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each WS In ThisWorkbook.Worksheets
Sheets(WS.Name).Select
Sheets(WS.Name).Copy
ActiveWorkbook.SaveAs Filename:="C:\" & WS.Name & ".txt", _
FileFormat:=xlText, CreateBackup:=False
ActiveWorkbook.Close
ThisWorkbook.Activate
Next
End Sub


Sub SaveWorkBookasTXT()
'Save all sheets in workbook and combine into one .txt file
Dim WS As Worksheet
Dim FS, A

Set FS = CreateObject("Scripting.FileSystemObject")

'cheek for folder exist and/or create
If FS.FolderExists("C:\TempOut") = False Then FS.CreateFolder
("C:\TempOut")

'save .txt files
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each WS In ThisWorkbook.Worksheets
Sheets(WS.Name).Select
Sheets(WS.Name).Copy
ActiveWorkbook.SaveAs Filename:="C:\TempOut\" & WS.Name &
".txt", _
FileFormat:=xlText, CreateBackup:=False
ActiveWorkbook.Close
ThisWorkbook.Activate
Next

'write bat file for file combine
Set A = FS.CreateTextFile("C:\TempOut\Combine.bat", True)
A.WriteLine ("type C:\TempOut\*.txt C:\Output.txt")
A.Close
'combine files
Shell "C:\TempOut\Combine.bat", vbNormalFocus
Application.Wait Now() + TimeValue("00:00:5")
'Kill tempory Dir
FS.deletefolder "C:\TempOut"

End Sub

'Change any .txt to .csv and FileFormat:=xlText to
FileFormat:=xlCSVWindows
cheers


--
D_Rennie
------------------------------------------------------------------------
D_Rennie's Profile: 1412
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=179039

Microsoft Office Help

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
export excel colonm to a single text file [email protected] Excel Discussion (Misc queries) 1 December 20th 08 10:36 AM
ExportAsFixedFormat for Multiple Sheets in a Single Excel File ivanL Excel Programming 2 May 22nd 08 05:38 AM
ExportAsFixedFormat for Multiple Sheets in a Single Excel File ivanL Excel Worksheet Functions 2 February 12th 08 07:42 PM
Export many sheets to one text file JJMNZ76 Excel Programming 0 October 25th 06 07:37 PM
Export multiple sheets to 1 csv file. Mark Bath Excel Programming 4 January 14th 05 03:09 AM


All times are GMT +1. The time now is 03:24 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"