+ Reply to Thread
Results 1 to 3 of 3

Thread: Split worksheets to separate files

  1. #1
    Registered User
    Join Date
    02-07-2011
    Location
    Oklahoma
    MS-Off Ver
    Excel 2007
    Posts
    2

    Split worksheets to separate files

    Hello all. I am working on a project that is two part. I am working with Excel 2007. I have a workbook that has 50 or so worksheets that I need to split and save as individual files. I found the following code online. It works fine, however, I need the "new" workbooks to be saved as Excel 97-2003 files. What do I need to add to this to make that happen?

    Sub splitsheettoworkbook()
    
    Dim wbDest As Workbook
    Dim wbSource As Workbook
    Dim sht As Worksheet 'Could be chart, worksheet, Excel 4.0 macro,etc.
    Dim strSavePath As String
    
    On Error GoTo ErrorHandler
    
    Application.ScreenUpdating = False 'Don't show any screen movement
    
    strSavePath = "C:\Excel Worksheets\" 'Change this to suit your needs
    
    Set wbSource = ActiveWorkbook
    
    For Each sht In wbSource.Sheets
    sht.Copy
    Set wbDest = ActiveWorkbook
    wbDest.SaveAs strSavePath & sht.Name
    wbDest.Close 'Remove this if you don't want each book closed after saving.
    Next
    
    Application.ScreenUpdating = True
    
    Exit Sub
    
    ErrorHandler: 'Just in case something hideous happens
    MsgBox "An error has occurred. Error number=" & Err.Number & ". Error description=" & Err.Description & "."
    
    End Sub
    Part Two is this: I have another file that I'm needing to split as well. However, the information in this workbook is organized in a Pivot Table. I have utilized the 'Show Report Filter Pages' to have the information on separate worksheets so that I can split the file. Will the above code (with the modification to save in 97-2003 format) work with the Pivot Table?
    Last edited by ksteffin; 02-25-2011 at 06:07 PM.

  2. #2
    Forum Contributor
    Join Date
    03-28-2008
    Posts
    161

    re: Splitting worksheets to separate files

    Try
    wbDest.SaveAs strSavePath & sht.Name
    change this to
    wbDest.SaveAs strSavePath & sht.Name & ".xls"

  3. #3
    Registered User
    Join Date
    02-07-2011
    Location
    Oklahoma
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Split worksheets to separate files

    That works great! One more question. The original workbook contains reports that I need to split and send out each month. If i wanted to add "March Reports" to the sheet name only when saving it, how would I do that? Could I add "March Reports" like this?

    wbDest.SaveAs strSavePath & sht.Name "March Reports" & ".xls"

    Thanks for your help, aravindhan_31!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0