Free Microsoft Excel 2013 Quick Reference

Export as csv file enclosed quotes Results

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.


I have a macro that exports a file to a CSV file with the fields enclosed in quotes, however there in items in some of the fields that are already quoted is there a way to modify this macro to ignore quoted items:

for ex: <ul class="test></ul>
is becoming
<ul class=""test""></ul>

Public Sub OutputQuotedCSV()
Const QSTR As String = """"
Dim myRecord As Range
Dim myField As Range
Dim vFilename As Variant
Dim nFileNum As Long
Dim sOut As String

'Get a filename to save as
vFilename = Application.GetSaveAsFilename(filefilter:="Microsoft CSV files,*.csv", _
Title:="Save as CSV with fields in double quotes")

If vFilename = False Then Exit Sub 'User chose Cancel

nFileNum = FreeFile
Open vFilename For Output As #nFileNum
For Each myRecord In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With myRecord
For Each myField In Range(.Cells(1), _
Cells(.Row, 256).End(xlToLeft))
sOut = sOut & "," & QSTR & _
Replace(myField.Text, QSTR, QSTR & QSTR) & QSTR
Next myField
Print #nFileNum, Mid(sOut, 2)
sOut = Empty
End With
Next myRecord
Close #nFileNum
End Sub
nevermind it works correctly

Hi Ozgriders, I need to export values directly from a user-defined array variable to a csv-file (without publishing array-values into a worksheet) . The code supplied below needs adjustments to allow this. After these adjustments, the desired output from this VBA-code would be:

1st row in CSV File has field-headings: “DateX”,"Number1”, ”Text1” in accordance with the names of the components of the user-defined array-variable (nb: component-names will vary, hence the need for a VBA script to automate this)Subsequent rows in the CSV file contain values from the array-variableNote: when exporting, I need to distinguish whether the data is a string (to be enclosed by quotes) or numeric or date (not to be enclosed by quotes). I’ve used the Val() expression here but it doesn’t work for the date (when exported, it’s enclosed by # symbol). I need the date-values published into the CSV file as xx/xx/xxxx format & not enclosed by quotes.Many thanks - code follows (changes are needed for the “ExportRange” procedure, first two are for information. Regards, Peter.

Type sample_type 
    DateX As Date 
    Number1 As Long 
    Text1 As String 
End Type 
Public myArray(1 To 3) As sample_type 
Sub Load_values_2_myArray() 
    Dim i As Long 
    For i = 1 To 3 
        With myArray(i) 
            .DateX = Date + i 
            .Number1 = Rnd() 
            .Text1 = "blah" & i 
        End With 
    Next i 
End Sub 
Sub Export() 
     'Ozgidders: This procedure is setup to fetch values from a selected range
     'What changes are needed to make it fetch values from the above user-defined
     'array and:
     '(1)save the array component-names as the field-names in the 1st line of the CSV file
     '(2)publish the array values in the remaining lines of the CSV file?
     'alternative code to below is welcomed.
    Dim Filename As String 
    Dim NumRows As Long, NumCols As Integer 
    Dim r As Long, c As Integer 
    Dim Data 
    Dim ExpRng As Range 
    Set ExpRng = Application.Intersect(Selection, ActiveSheet.UsedRange) 
    NumCols = ExpRng.Columns.Count 
    NumRows = ExpRng.Rows.Count 
    Filename = "C:" & "textfile.csv" 
    Open Filename For Output As #1 
    For r = 1 To NumRows 
        For c = 1 To NumCols 
            Data = ExpRng.Cells(r, c).Value 
            If IsNumeric(Data) Then Data = Val(Data) 
            If IsEmpty(ExpRng.Cells(r, c)) Then Data = "" 
            If c  NumCols Then 
                Write #1, Data; 
                Write #1, Data 
            End If 
        Next c 
    Next r 
    Close #1 
    MsgBox ExpRng.Count & " cells were exported to " & Filename, vbInformation 
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines

I have excel sheet with text in it.
I have to export or save it as csv file so that all the columns are
separated by comma and values in columns are enclosed in quotes.
The csv file should be like:
John Doe,"home"

How can this be achieved?

When you save a file from Excel as a Text (.txt) file, it uses the Tab character as the delimiter. Is there a way to save it with a comma delimeter and enclose non numeric fields in quotes. I am aware of the .csv option, but it doesn't enclose the field in quotes.

Here's my problem. I'm using Excel output to feed Access input. I have more than 100,000 records, so I'm forced to cut and paste two outputs from Excel into one big text file, which will be used as import file into Access. When I combine the two text files from my text editor, it remembers the tabs and Access rejects the imported file (saying not in expected format).

Its odd, because when you export a .txt file FROM Access, the data looks like:

"field one","field two"

But when you save a file as .txt in Excel, it looks like

field one[tab]field two

Any suggestions would be appreciated.

My credit card company has an export feature. One of the options is ".csv
(Excel). This used to give me a nice clean spreadsheet with each column of
information in a separate Excell column. I guess it converted on the fly or
something. But now it seems to be a "comma delimited text file" In other
words, only the first Excel cell in each row has data in it, and it looks
like this in each row (the first row has headings).
1,"03/24/2005","HARVARD CS","Credit","$39.95". What can I do to get all
those comma delimited items into separate cells?
I've tried contacting the Credit Card company to no avail. Is the fact that
the first item is not enclosed in quotes significant?

This is actually a repost, as I tried to pursue this when I first discovered
it with last month's statement, but didn't get answers that provided a

No luck finding an answer? You could always try Google.