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
Bookmarks