+ Reply to Thread
Results 1 to 2 of 2

Macro for Saving WorkSheets

  1. #1
    Registered User
    Join Date
    11-06-2008
    Location
    New York
    Posts
    2

    Macro for Saving WorkSheets

    I have a user that loves to keep a single workbook with numerous worksheets for each week. This worksheet hold information for about 2 years of data. Each worksheet is named mm-dd-yy with the date being the first day of the week. I need to create a macro that takes the past worksheets and saves them to a different file with the file name being the mm-dd-yy of the worksheet that it contains.

    Any help or advice would be greatly appreciated.

    Thanks
    Last edited by VBA Noob; 11-06-2008 at 02:04 PM.

  2. #2
    Registered User
    Join Date
    11-06-2008
    Location
    New York
    Posts
    2
    I think I may have found a solution.

    Sub CreateWorkbooks()
    'Creates an individual workbook for each worksheet in the active workbook.
    Dim wbDest As Workbook
    Dim wbSource As Workbook
    Dim sht As Object '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:\Temp\" '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.
    ActiveSheet.Delete
    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

+ 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.6.0 RC 1