+ Reply to Thread
Results 1 to 4 of 4

Macro that should create csvs of all the sheets of a workbook doesn't work! help!

Hybrid View

scantron Macro that should create csvs... 06-15-2012, 10:48 AM
vandan_tanna Re: Macro that should create... 06-15-2012, 12:15 PM
vandan_tanna Re: Macro that should create... 06-15-2012, 12:46 PM
vandan_tanna Re: Macro that should create... 06-15-2012, 12:41 PM
  1. #1
    Registered User
    Join Date
    01-20-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    30

    Macro that should create csvs of all the sheets of a workbook doesn't work! help!

    Sub Make_New_Books()
    Dim w As Worksheet
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    FileExtStr = ".csv": FileFormatNum = 6
    For Each w In ActiveWorkbook.Worksheets
    w.Copy
    With ActiveWorkbook
    .SaveAs Filename:="C:\8350\" & "8350" & "_" & w.Name & FileExtStr
    .Close
    End With
    Next w
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub
    The line that is throwing an error is ".SaveAs Filename:="C:\8350\" & "8350" & "_" & w.Name & FileExtStr
    .Close"

  2. #2
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Macro that should create csvs of all the sheets of a workbook doesn't work! help!

    Here are changed I have made along with comments on why I made the changes.

    Deleted..see next post
    Also, please ensure that you do have a directory called 8350 under C:\
    Last edited by vandan_tanna; 06-15-2012 at 12:47 PM.
    Regards,
    Vandan

  3. #3
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Macro that should create csvs of all the sheets of a workbook doesn't work! help!

    How about this one?

    Option Explicit   'good programming practice
    
    Sub Make_New_Books()
    
    Dim w As Worksheet
    Dim FileExtStr As String
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    
    On Error GoTo ErrorHandler  'error handling
    
    'following is not used and therefore not needed
    'FileExtStr = ".csv": FileFormatNum = 6
    
    For Each w In ThisWorkbook.Worksheets
        
        w.Copy
        
        
        With ActiveWorkbook
            .SaveAs Filename:="C:\8350\8350_" & w.Name, FileFormat:=xlCSV
            .Close
        End With
    Next w
    
    'Normal exit - exit here if no error
    ErrorExit:
        Application.DisplayAlerts = True
        Application.ScreenUpdating = True
        Exit Sub
    
    'If error display them and then exit through above code to reset alerts and screenupdating
    ErrorHandler:
        MsgBox Err.Number & ": " & Err.Description
        GoTo ErrorExit
    
    End Sub
    Please ensure that you have a directory named '8350' under C:\
    Last edited by vandan_tanna; 06-15-2012 at 12:49 PM.

  4. #4
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Macro that should create csvs of all the sheets of a workbook doesn't work! help!

    redoing the code...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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