How do I run this to get a quoted csv file?

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
 
B

Bernie Deitrick

Walter,

Here is a link describing the steps for installing a macro:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

HTH,
Bernie
MS Excel MVP


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top