+ Reply to Thread
Results 1 to 4 of 4

Save Worksheets as CSV

Hybrid View

jregan Save Worksheets as CSV 06-09-2010, 04:04 PM
Leith Ross Re: Save Worksheets as CSV 06-09-2010, 05:01 PM
Basz Re: Save Worksheets as CSV 06-11-2010, 07:09 AM
pike Re: Save Worksheets as CSV 06-11-2010, 07:11 AM
  1. #1
    Registered User
    Join Date
    08-10-2009
    Location
    Hamilton
    MS-Off Ver
    Excel 2003
    Posts
    7

    Save Worksheets as CSV

    Hi, below I've included a VB script which saves each worksheet within a workbook as a separate CSV file. I would like help modifying this script so only one of my worksheets called "budgetcsv" saves.
    Public Sub DoTheExport()
    Dim FName As Variant
    Dim Sep As String
    Dim wsSheet As Worksheet
    Dim nFileNum As Integer
    Dim csvPath As String
    
    
    Sep = InputBox("Enter a single delimiter character (e.g., comma or semi-colon)", _
    "Export To Text File")
    'csvPath = InputBox("Enter the full path to export CSV files to: ")
    
    csvPath = GetFolderName("Choose the folder to export CSV files to:")
    If csvPath = "" Then
        MsgBox ("You didn't choose an export directory. Nothing will be exported.")
        Exit Sub
    End If
    
    For Each wsSheet In Worksheets
    wsSheet.Activate
    nFileNum = FreeFile
    Open csvPath & "\" & _
      wsSheet.Name & ".csv" For Output As #nFileNum
    ExportToTextFile CStr(nFileNum), Sep, False
    Close nFileNum
    Next wsSheet
    End Sub
    Last edited by Leith Ross; 06-09-2010 at 04:43 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Save Worksheets as CSV

    Hello jregan,

    The macro will now export "Budget" as a CSV file.

    Public Sub DoTheExport()
    
      Dim FName As Variant
      Dim Sep As String
      Dim wsSheet As Worksheet
      Dim nFileNum As Integer
      Dim csvPath As String
    
    
        Sep = InputBox("Enter a single delimiter character (e.g., comma or semi-colon)", "Export To Text File")
       
        'csvPath = InputBox("Enter the full path to export CSV files to: ")
        csvPath = GetFolderName("Choose the folder to export CSV files to:")
       
        If csvPath = "" Then
          MsgBox ("You didn't choose an export directory. Nothing will be exported.")
          Exit Sub
        End If
    
        Set wsSheet = Worksheets("Budget")
        
        nFileNum = FreeFile
          Open csvPath & "\" & wsSheet.Name & ".csv" For Output As #nFileNum
            ExportToTextFile CStr(nFileNum), Sep, False
          Close nFileNum
       
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    07-28-2004
    Posts
    8

    Re: Save Worksheets as CSV

    hi jregan,

    Sorry to ask, but I'd be interested in the complete code in order to use this very helpful script as well.
    Would you care to post it here?

    Many thanks,
    Basz

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Save Worksheets as CSV

    Basz

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

    You can start you own thread with specific issues to be addressed
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

+ 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