export as csv file enclosed quotes?

nikko50

Board Regular
Joined
Mar 3, 2004
Messages
155
Hi there guys:)
If I have a xpreadsheet how can I save as a csv file with each column enclosed in quotes?? I can save the file as a csv but the fields are not enclosed in double quotes like below.

"TOM CLARK","58 MAIN ST.","NORMANTOWN","CA","83345"
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I got this code off of the msdn website a few years ago. Should do what you are looing for.

Sub CSVFile()

Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim FName As Variant
FName = Application.GetSaveAsFilename("", "CSV File (*.csv), *.csv")

If FName <> False Then
ListSep = Application.International(xlListSeparator)
If Selection.Cells.Count > 1 Then
Set SrcRg = Selection
Else
Set SrcRg = ActiveSheet.UsedRange
End If
Open FName For Output As #1
For Each CurrRow In SrcRg.Rows
CurrTextStr = ""
For Each CurrCell In CurrRow.Cells
CurrTextStr = CurrTextStr & """" & CurrCell.Value & """" & ListSep
Next
While Right(CurrTextStr, 1) = ListSep
CurrTextStr = Left(CurrTextStr, Len(CurrTextStr) - 1)
Wend
Print #1, CurrTextStr
Next
Close #1
End If
End Sub

HTH
Cal
 
Upvote 0
I stumbled on this solution. Thank you for posting it, works great, I LOVE it.
I use it to prepare the input file to upload data in my MySql DB.

Thanks!!

Darrab
 
Upvote 0
Sorry for resurrecting an old thread but this is not working for me. I have date-fields that i have formattet so that mariadb (mysql) will accept them.
When i export from Excel i get the correct format. Using the macro i get the quotes right but the dates are messed up :(
Any solutions to this?
 
Upvote 0

Forum statistics

Threads
1,223,927
Messages
6,175,431
Members
452,641
Latest member
Arcaila

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top