W
walterbyrd
I am trying to save a ms-excel spreadsheet as a csv file with quoted
values, i.e.
"1","2", "3","4"
But, I can not do that directly. I found a script which is supposed to
do that, but I do not know how to run an excel script. Do I put the
script in a cell, or what?
Here is the script:
Sub subExportCSV()
On Error GoTo subexport_exit
Dim strDelimiter As String
strDelimiter = Chr(9)
Dim strQualifier As String
strQualifier = “”"”
Dim arrRng
arrRng = ActiveSheet.UsedRange.Value
Dim f As String
Dim i As Long
Dim j As Long
Dim strTemp As String
f = InputBox(”Enter a filename for saving”, , “c:\test.csv”)
If Trim(f) = “” Then Exit Sub
Open f For Output As #1
strTemp = “”
For i = 1 To UBound(arrRng, 1)
strTemp = “”
For j = 1 To UBound(arrRng, 2)
strTemp = strTemp & strQualifier & arrRng(i, j) & strQualifier
& strDelimiter
Next j
Print #1, Left(strTemp, Len(strTemp) - Len(strDelimiter))
Next i
subexport_exit:
Close #1
End Sub
values, i.e.
"1","2", "3","4"
But, I can not do that directly. I found a script which is supposed to
do that, but I do not know how to run an excel script. Do I put the
script in a cell, or what?
Here is the script:
Sub subExportCSV()
On Error GoTo subexport_exit
Dim strDelimiter As String
strDelimiter = Chr(9)
Dim strQualifier As String
strQualifier = “”"”
Dim arrRng
arrRng = ActiveSheet.UsedRange.Value
Dim f As String
Dim i As Long
Dim j As Long
Dim strTemp As String
f = InputBox(”Enter a filename for saving”, , “c:\test.csv”)
If Trim(f) = “” Then Exit Sub
Open f For Output As #1
strTemp = “”
For i = 1 To UBound(arrRng, 1)
strTemp = “”
For j = 1 To UBound(arrRng, 2)
strTemp = strTemp & strQualifier & arrRng(i, j) & strQualifier
& strDelimiter
Next j
Print #1, Left(strTemp, Len(strTemp) - Len(strDelimiter))
Next i
subexport_exit:
Close #1
End Sub