+ Reply to Thread
Results 1 to 3 of 3

How can I save a range as its own .csv?

  1. #1
    Registered User
    Join Date
    03-04-2005
    Posts
    3

    Question How can I save a range as its own .csv?

    I'm an oracle programmer so I dont know much about VBA but I'm trying to get through this. Our users will have a 1 worksheet excel file which will be uploaded to an oracle database. I'm going to have a button on the worksheet that will save the file as a .csv, upload it automatically, and close the excel file. The problem is the number of rows will vary so I only want to save a certain range on the worksheet.

    Do I need to create a new worksheet for which to copy the range, or can I directly save the file as a certain range? If I have to make a new workbook, can this be done in the background so the user doesn't see what is going on? Any help would be appreciated. This is what I have so far.

    Sub SaveAsCSV()
    Const ctTitle = "Finished?"
    Dim lStr_NewName As String
    Dim rng As Excel.Range

    rng = ws.Range("A6:L17")

    lStr_NewName = Left(ThisWorkbook.Name, InStr(1, LCase(ThisWorkbook.Name), ".xls") - 1) & _
    " - " & Format(Now, "yyyymmdd hhmmss")

    If vbYes = MsgBox("Publish " & lStr_NewName & ".csv ?", vbYesNo + vbExclamation, ctTitle) Then
    ActiveWorkbook.Save
    ActiveWorkbook.SaveAs lStr_NewName, FileFormat:=xlCSV
    MsgBox "File Sent.", vbOKOnly + vbInformation, "Closing"
    ActiveWorkbook.Close Savechanges:=False
    Else
    MsgBox "File Not Sent.", vbOKOnly + vbInformation, "Canceled"
    End If

    End Sub

  2. #2
    Forum Contributor
    Join Date
    11-16-2004
    Posts
    282
    You need to copy the data range only to a new workbook, then save it as a .csv file. See my updated version of your code below (it will be transparent to the user except for the dialogs):
    Please Login or Register  to view this content.
    Hope this helps,
    theDude
    Last edited by theDude; 03-04-2005 at 05:24 PM.

  3. #3
    Registered User
    Join Date
    03-04-2005
    Posts
    3
    Awesome! Thanks, Dude!

+ 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