Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 16
Default How to save an entireworkbook to individual text files?

I regularily work with workbooks that contain well over 20 worksheets per
book. After working with the data I always have to save each 'sheet' as an
individual *.txt file. All the sheets are saved using the worksheet name.

Is there any way to automate this process, ie. save all worksheets to a
respective *.txt file. For example, 20 sheets in a book, will result in 20
seperate *.txt files.

Steve
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default How to save an entireworkbook to individual text files?

You could use a macro:

Option Explicit
Sub Testme02()

Dim Wks As Worksheet

For Each Wks In ActiveWorkbook.Worksheets
Wks.Copy 'to a new workbook
With ActiveSheet 'the new sheet in the new workbook
.Parent.SaveAs Filename:="C:\temp\" & .Name & ".txt", _
FileFormat:=xlTextWindows
.Parent.Close savechanges:=False
End With
Next Wks

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

This also assumes that the worksheet names are valid OS names and that the
C:\Temp folder already exists.




stevieb wrote:

I regularily work with workbooks that contain well over 20 worksheets per
book. After working with the data I always have to save each 'sheet' as an
individual *.txt file. All the sheets are saved using the worksheet name.

Is there any way to automate this process, ie. save all worksheets to a
respective *.txt file. For example, 20 sheets in a book, will result in 20
seperate *.txt files.

Steve


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 16
Default How to save an entireworkbook to individual text files?

I think the code you wrote is a little to complicated for the task. I dont
see why you cant traverse through the active workbook, and just save each
file. Would it possible to do that instead of making a new workbook each
time?

"Dave Peterson" wrote:

You could use a macro:

Option Explicit
Sub Testme02()

Dim Wks As Worksheet

For Each Wks In ActiveWorkbook.Worksheets
Wks.Copy 'to a new workbook
With ActiveSheet 'the new sheet in the new workbook
.Parent.SaveAs Filename:="C:\temp\" & .Name & ".txt", _
FileFormat:=xlTextWindows
.Parent.Close savechanges:=False
End With
Next Wks

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

This also assumes that the worksheet names are valid OS names and that the
C:\Temp folder already exists.




stevieb wrote:

I regularily work with workbooks that contain well over 20 worksheets per
book. After working with the data I always have to save each 'sheet' as an
individual *.txt file. All the sheets are saved using the worksheet name.

Is there any way to automate this process, ie. save all worksheets to a
respective *.txt file. For example, 20 sheets in a book, will result in 20
seperate *.txt files.

Steve


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default How to save an entireworkbook to individual text files?

If you go through the sheets in the active workbook and save each as a .txt
file, watch what happens to the filename each time you do the save.

Or just look at the filename after the last worksheet has been saved.

It's much easier to avoid the problem than to work around it (in my opinion).

stevieb wrote:

I think the code you wrote is a little to complicated for the task. I dont
see why you cant traverse through the active workbook, and just save each
file. Would it possible to do that instead of making a new workbook each
time?

"Dave Peterson" wrote:

You could use a macro:

Option Explicit
Sub Testme02()

Dim Wks As Worksheet

For Each Wks In ActiveWorkbook.Worksheets
Wks.Copy 'to a new workbook
With ActiveSheet 'the new sheet in the new workbook
.Parent.SaveAs Filename:="C:\temp\" & .Name & ".txt", _
FileFormat:=xlTextWindows
.Parent.Close savechanges:=False
End With
Next Wks

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

This also assumes that the worksheet names are valid OS names and that the
C:\Temp folder already exists.




stevieb wrote:

I regularily work with workbooks that contain well over 20 worksheets per
book. After working with the data I always have to save each 'sheet' as an
individual *.txt file. All the sheets are saved using the worksheet name.

Is there any way to automate this process, ie. save all worksheets to a
respective *.txt file. For example, 20 sheets in a book, will result in 20
seperate *.txt files.

Steve


--

Dave Peterson


--

Dave Peterson
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 do I save an individual page in a workbook? Sharon Williams Excel Worksheet Functions 2 December 14th 06 02:14 PM
MACRO HELP: Save All Sheets To Individual Workbooks Zorro Excel Discussion (Misc queries) 3 September 2nd 06 07:06 PM
Create individual files from a row GrahamN Excel Discussion (Misc queries) 3 July 4th 05 10:01 PM
Help importing text files into individual cells saybut Excel Discussion (Misc queries) 4 May 31st 05 03:24 PM
How can I make Excel Files save as the text appers in a cell, can. I khan Excel Discussion (Misc queries) 1 February 1st 05 07:34 PM


All times are GMT +1. The time now is 12:59 PM.

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

About Us

"It's about Microsoft Excel"