Excel Save CSV with double quotes

yes, i’m saving this snippet here because it actually works! just insert into the vba for excel, run and remember that it first asks for the source of the file to run the code on, and NOT to output the current file as ‘save as’. get it? good.

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

cameron works!

okay, well more like watches spongebob on a laptop, drinking root beer and belching loudly. last day before our trip to canada and figured i’d oblige camerons desire to come in to work with me while i wrap stuff up before being gone for 2 weeks. he is utterly disinterested in any actual work here, although the promise of jamming things in the shredder later today is enticing….