Results 1 to 5 of 5

Thread: Exporting A Worksheet To A CSV File / Save Workbook As CSV File

  1. #1
    Banned
    Join Date
    May 2013
    Posts
    17
    Rep Power
    0

    Exporting A Worksheet To A CSV File / Save Workbook As CSV File

    Hello,

    I would like to ask help for the vba code to export a single worksheet to a csv file. And the user will save it manually. I mean, User will be the one to put the file name, and look for the destination of the file where to be saved.

    Thank you in advance,

    Jeffrey

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    This will only work for the first sheet of your workbook.

    Code:
    Sub SaveAsCSV()
    
        ActiveWorkbook.SaveAs Application.GetSaveAsFilename(, "Comma Seperated Value File (*.csv), *.csv"), xlCSV
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Banned
    Join Date
    May 2013
    Posts
    17
    Rep Power
    0
    It shows an error " Object Required "

    Here's my code.

    Code:
    Sub export()
    
    
    Application.DisplayAlerts = False
    
    sFileName = "CLASSIFIED.csv"
    
    Sheets("CLASSIFIED").Range("A1:AN1000").Copy
    
    
    Set WB = Workbooks.Add
    With WB
        .Title = "Classified"
        .Sheets(1).Select
        ActiveSheet.Paste
        ActiveWorksheet.SaveAs Application.GetSaveAsFilename("", "Comma Seperated Value File (*.csv), *.csv"), xlCSV
        
    End With
    
    Application.DisplayAlerts = True
    
    End Sub
    Last edited by Excel Fox; 06-20-2013 at 04:22 PM. Reason: Code Tags

  4. #4
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    13
    Code:
    Sub export()
    
        Application.DisplayAlerts = False
        Sheets("CLASSIFIED").Copy
        With ActiveWorkbook
            .Title = "Classified"
            .SaveAs Application.GetSaveAsFilename("CLASSIFIED", "Comma Seperated Value File (*.csv), *.csv"), xlCSV
            .Close True
        End With
        Application.DisplayAlerts = True
    
    End Sub

  5. #5
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    A sheet doesn't have a SaveAs method. Why would you change the SaveAs method I used for the workbook, on to a worksheet? I'm refering to Post #3 above.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. Save Worksheets As New File To Specific Folder
    By k0st4din in forum Excel Help
    Replies: 18
    Last Post: 06-08-2013, 04:24 PM
  2. Save Excel 2010 File In CSV Format VBA
    By mag in forum Excel Help
    Replies: 7
    Last Post: 01-08-2013, 07:16 PM
  3. Importing a csv File to a range
    By SDruley in forum Excel Help
    Replies: 21
    Last Post: 11-20-2012, 04:54 PM
  4. Replies: 1
    Last Post: 06-02-2011, 10:38 AM
  5. Save File In CSV Format VBA
    By Raj Kumar in forum Excel Help
    Replies: 3
    Last Post: 06-01-2011, 07:22 AM

Tags for this Thread

Posting Permissions

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