Results 1 to 5 of 5

export as csv file enclosed quotes?

This is a discussion on export as csv file enclosed quotes? within the Excel Questions forums, part of the Question Forums category; Hi there guys If I have a xpreadsheet how can I save as a csv file with each column enclosed ...

  1. #1
    Board Regular
    Join Date
    Mar 2004
    Location
    usa
    Posts
    132

    Default export as csv file enclosed quotes?

    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"

  2. #2
    Board Regular Cbrine's Avatar
    Join Date
    Dec 2003
    Location
    Brampton
    Posts
    3,191

    Default Re: export as csv file enclosed quotes?

    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
    Xcelerated Solutions
    Office Automation Solutions for the Toronto Area

  3. #3
    New Member
    Join Date
    Oct 2011
    Posts
    1

    Thumbs up Re: export as csv file enclosed quotes?

    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

  4. #4
    New Member
    Join Date
    Jan 2015
    Posts
    1

    Default Re: export as csv file enclosed quotes?

    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?

  5. #5
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    71,098

    Default Re: export as csv file enclosed quotes?

    Welcome to MrExcel.

    Try using CurrCell.Text instead of CurrCell.Value.
    Microsoft MVP - Excel

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com