LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
CTB CTB is offline
external usenet poster
 
Posts: 3
Default Save each sheet of multi-sheet workbook as a single-sheet workbook

MS Office Excel 2007

Hello all,

I have 5 huge workbooks each with 12 sheets of monthly data (sheet
names are in the format of "mmm yyyy"). I'm trying to split them up
into 12 not-as-huge single-sheet workbooks.

When I use "Worksheet.SaveAs" (see code pasted at the end), all 12
sheets are saved in the new workbook with the desired name...not just
the desired sheet.

How do I create 12 single-sheet workbooks from 1 12-sheet workbook?
Do I need to copy/move sheet to new workbook and save new workbook
with desired name?

Thanks for any help anyone can provide,

CTB





******** Code: ********

Option Explicit

Sub SplitSheets()
Dim pfso As New FileSystemObject
Dim pfsoSourceFolder As Folder
Dim pfsoDestFolder As Folder
Dim pstrDestFolder As String
Dim pfsoFile As File

Dim pwkbSource As Workbook
Dim pwksSource As Worksheet

Dim pstrDate As String
Dim pdteDate As Date

Dim pstrDestFileName As String


pstrDestFolder = "New Folder"
Set pfsoFile = pfso.GetFile(Application.GetOpenFilename)
Set pfsoSourceFolder = pfsoFile.ParentFolder
Set pfsoDestFolder = pfso.GetFolder(pfsoSourceFolder.Path &
Application.PathSeparator & pstrDestFolder)

For Each pfsoFile In pfsoSourceFolder.Files
Set pwkbSource = Application.Workbooks.Open(pfsoFile.Path, ,
True)

For Each pwksSource In pwkbSource.Worksheets
'pwksSource.Activate
pstrDate = pwksSource.Name
pdteDate = DateValue(pstrDate)
pdteDate = DateSerial(Year(pdteDate), Month(pdteDate) + 1,
0)
pstrDate = Format(pdteDate, "yyyy-mm-dd")

pstrDestFileName = pfsoDestFolder.Path &
Application.PathSeparator & pstrDate
'pstrDestFileName = pfsoDestFolder.Path &
Application.PathSeparator & pstrDate & ".xlsx"

pwksSource.SaveAs pstrDestFileName, xlOpenXMLWorkbook

Next pwksSource

pwkbSource.Close False
Next pfsoFile
End Sub
 
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
Help with multi sheet workbook Sportinus Excel Worksheet Functions 2 July 10th 08 01:41 PM
Save a single file webpage of each visible sheet in a workbook Matt Excel Programming 4 June 30th 06 05:44 PM
how do i save a single sheet from my workbook? eyesonly1965[_14_] Excel Programming 5 May 14th 06 08:30 PM
Save a single sheet from a workbook JAMES T. Excel Discussion (Misc queries) 2 January 25th 05 02:16 PM
print and save a single sheet from a workbook using a commandbutt. bibio_ Excel Programming 1 November 13th 04 12:53 PM


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