I am trying to export a bit of data from an excel workbook via API PUT. The specific API that I am using requires the data to be in CSV.
I have code from this site that converts a range of cells into a CSV.
Sub ExportRangetoFile()
'Update 20150628
Dim Rng As Range
Dim WorkRng As Range
Dim xFile As Variant
Dim xFileString As String
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address,
Type:=8)
Application.ActiveSheet.Copy
Application.ActiveSheet.Cells.Clear
WorkRng.Copy Application.ActiveSheet.Range("A1")
Set xFile = CreateObject("Scripting.FileSystemObject")
xFileString = Application.GetSaveAsFilename("", filefilter:="Comma Separated
Text (*.CSV), *.CSV")
Application.ActiveWorkbook.SaveAs Filename:=xFileString, FileFormat:=xlCSV,
CreateBackup:=False
End Sub
1st Issue: This example requires a couple extra steps after running; selecting the range and saving/naming the file. I have a constant range of cells that will be converted to CSV (although they do not have constant value) and I don't really want the user to do anything with the CSV. I am trying to make this as automated as possible so others can just click a button in the workbook to do this export. How can I do what this site shows but completely automated via macros and/or modules in VBA?
2nd Issue: If a solution to issue 1 is found, and a CSV file is saved after every time running that macro, is it possible to PUT that CSV via the API call in the same workbook the file was created? Again I am trying to make everything automated to make it as easy as possible for the people who will be using this workbook the most. Perhaps all of these things can be done in one macro or module.
Clarification
I am asking for help with creating a CSV from a range of cells by just running a macro and not clicking any saves or file naming. Secondly, I am just asking if it is possible and if it is best practice to send this CSV file through an API call in the same workbook or even the same macro where it can all be done with just one form click. I don't need help with the API call specifics... yet.