Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Min Min is offline
external usenet poster
 
Posts: 40
Default How do I save each sheet as a separate .xls file by using macro?

I have a workbook that has 100 sheets. I want to save each sheet as a
separate xls file. Even though I could save each by copying into new
worksheet and save manually, I am looking for a way to automate it by using
script. Can anyone help?
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default How do I save each sheet as a separate .xls file by using macro?

Here's how I would approach it:
Dim separate objects for the application, the ActiveWorkbook, a new
workbook, and worksheet.
Set the application object and the ActiveWorkbook object.
Then loop through the worksheets coolection of the ActiveWorkbook:
For Each "ws" in "awb".Worksheets
Select the worksheet and copy
Set the "newwb" object to a new workbook
Paste
"newwb".SaveAs (you'll have to set a string to a filename)
"newwb".Close
Next "ws"
"awb".Close DoNotSaveChanges

You might try walking through the copy, new workbook, paste, saveas, close
once with the macro recorder on. Then you can go back into it, add the
objects and the filename string, and put the loop in.

Ed

"Min" wrote in message
...
I have a workbook that has 100 sheets. I want to save each sheet as a
separate xls file. Even though I could save each by copying into new
worksheet and save manually, I am looking for a way to automate it by

using
script. Can anyone help?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default How do I save each sheet as a separate .xls file by using macro?

Here is some code to do that for you... It will not overwrite any files
without asking first. It uses the tab name for the file name. I have set the
default path as C:\. You can change that...

Private Const strPATH As String = "C:\"

Private Sub SaveSheets()
Dim wks As Worksheet

For Each wks In Worksheets
wks.Copy
ActiveWorkbook.SaveAs strPATH & wks.Name
ActiveWorkbook.Close
Next wks

End Sub


"Min" wrote:

I have a workbook that has 100 sheets. I want to save each sheet as a
separate xls file. Even though I could save each by copying into new
worksheet and save manually, I am looking for a way to automate it by using
script. Can anyone help?

  #4   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default How do I save each sheet as a separate .xls file by using macro?

Okay - much simpler than mine! 8{ (But I'm used to that!)
But how do you get just the copied sheet into a new workbook? Won't
ActiveWorkbook.SaveAs save the whole file, not just the sheet as a new file?

Ed

"Jim Thomlinson" wrote in message
...
Here is some code to do that for you... It will not overwrite any files
without asking first. It uses the tab name for the file name. I have set

the
default path as C:\. You can change that...

Private Const strPATH As String = "C:\"

Private Sub SaveSheets()
Dim wks As Worksheet

For Each wks In Worksheets
wks.Copy
ActiveWorkbook.SaveAs strPATH & wks.Name
ActiveWorkbook.Close
Next wks

End Sub


"Min" wrote:

I have a workbook that has 100 sheets. I want to save each sheet as a
separate xls file. Even though I could save each by copying into new
worksheet and save manually, I am looking for a way to automate it by

using
script. Can anyone help?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default How do I save each sheet as a separate .xls file by using macr

wks.copy creates a new workbook with just that sheet in it. Same as right
click on that tab - Create Copy - In new Workbook.

This is now the active workbook. You can refernce the original workbook as
thisworkbook (but we don't need to in this case).

Save and close the active workbook and go on to the next sheet.

With a little practice comes ability. With a lot of practice comes simplicity.

"Ed" wrote:

Okay - much simpler than mine! 8{ (But I'm used to that!)
But how do you get just the copied sheet into a new workbook? Won't
ActiveWorkbook.SaveAs save the whole file, not just the sheet as a new file?

Ed

"Jim Thomlinson" wrote in message
...
Here is some code to do that for you... It will not overwrite any files
without asking first. It uses the tab name for the file name. I have set

the
default path as C:\. You can change that...

Private Const strPATH As String = "C:\"

Private Sub SaveSheets()
Dim wks As Worksheet

For Each wks In Worksheets
wks.Copy
ActiveWorkbook.SaveAs strPATH & wks.Name
ActiveWorkbook.Close
Next wks

End Sub


"Min" wrote:

I have a workbook that has 100 sheets. I want to save each sheet as a
separate xls file. Even though I could save each by copying into new
worksheet and save manually, I am looking for a way to automate it by

using
script. Can anyone help?






  #6   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default How do I save each sheet as a separate .xls file by using macr

With a little practice comes ability. With a lot of practice comes
simplicity

That's a mouthful, Jim. I will remember that. Thanks.
Ed

"Jim Thomlinson" wrote in message
...
wks.copy creates a new workbook with just that sheet in it. Same as right
click on that tab - Create Copy - In new Workbook.

This is now the active workbook. You can refernce the original workbook as
thisworkbook (but we don't need to in this case).

Save and close the active workbook and go on to the next sheet.

..

"Ed" wrote:

Okay - much simpler than mine! 8{ (But I'm used to that!)
But how do you get just the copied sheet into a new workbook? Won't
ActiveWorkbook.SaveAs save the whole file, not just the sheet as a new

file?

Ed

"Jim Thomlinson" wrote in

message
...
Here is some code to do that for you... It will not overwrite any

files
without asking first. It uses the tab name for the file name. I have

set
the
default path as C:\. You can change that...

Private Const strPATH As String = "C:\"

Private Sub SaveSheets()
Dim wks As Worksheet

For Each wks In Worksheets
wks.Copy
ActiveWorkbook.SaveAs strPATH & wks.Name
ActiveWorkbook.Close
Next wks

End Sub


"Min" wrote:

I have a workbook that has 100 sheets. I want to save each sheet as

a
separate xls file. Even though I could save each by copying into

new
worksheet and save manually, I am looking for a way to automate it

by
using
script. Can anyone 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
how do I get a macro to save a sheet and set the file name? MadasMax Excel Discussion (Misc queries) 1 September 16th 07 12:04 PM
How do I save part of a worksheet in a separate file? cleo Excel Worksheet Functions 3 May 15th 07 01:26 AM
Can I auto save to a separate file?(not the file I am working in) Jim Lynch Setting up and Configuration of Excel 1 August 14th 06 05:20 PM
How to save each sheet as a separate excel-file Audio_freak Excel Programming 4 January 4th 04 08:56 PM
Macro to insert values from a file and save another sheet as a .txt file Frank[_16_] Excel Programming 2 August 28th 03 01:07 AM


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