Save Excel as CSV with Double Quotes (3 Simplest Methods)

Saving CSV files with double quotes is necessary to avoid any misrepresentation. For example, consider the row of data USD,25,000,Model1. Here, the comma delimiter is a little confusing. Instead, USD,“25,000”,Model1 is easier to decipher. We’ll save the Excel file with values in double quotes so it can be ported to different applications easier.

excel save csv with double quotes


Save Excel as CSV with Double Quotes: 3 Quickest Ways

Method 1 – Use the Custom Format to Save Excel File as CSV with Double Quotes

Consider the following dataset. You want to save it as a CSV file with cell values wrapped in double-quotes.

Steps

  • Select the entire range (A1:B6) of the dataset.
  • Press Ctrl + 1 to open the Format Cells window.
  • Select the Custom format from the Number tab.
  • Enter \“#\”;\“@\” in the Type field.
  • Press OK.

Excel to CSV with Double Quotes Using Custom Format

  • Select File and choose Save As. Browse the desired location to save the file.
  • Enter a file name.
  • Choose CSV (Comma delimited) (*.csv) as the file type using the dropdown arrow.
  • Click on the Save button.

  • Go to the file’s location and open the CSV file with a text editor (such as Notepad).

  • You will see the following result containing some extra double-quotes.

  • Press Ctrl + H to open the Replace window.
  • Enter a double quote in the Find what field without any space in between them.
  • Keep the Replace with field empty and select Replace All.
  • You will get the desired result as follows.

Read More: How to Save Excel File as CSV with Commas


Method 2 – Use Windows PowerShell

Steps

  • Go to the worksheet that you want to save as a CSV file.
  • Select File and choose Save As.
  • Save the file with CSV (Comma delimited) (*.csv) as the file type using the dropdown arrow.
  • Click on the Save button.

Covert Excel files and save as CSV files

  • You will get the following result.

  • Hold the Shift key and right-click on any blank space in the location of the CSV file without double-quotes.
  • Click on Open PowerShell window here.

  • Copy the following command. You need to change the file names (Sales1.csv and Sales2.csv) based on your files.
import-csv Sales1.csv | export-csv Sales2.csv  -NoTypeInformation -Encoding UTF8
  • Paste the copied code into the PowerShell window and press Enter.

Excel to CSV with Double Quotes Using Windows PowerShell

  • You will get the desired result as shown in the picture below.

Read More: Set Comma Instead of Semicolon as Delimiter in Excel CSV


Method 3 – Apply VBA Code for a CSV File with Double Quotes

Steps

  • Press Alt + F11 to open the VBA window.
  • Select Insert and pick Module from the ribbon. This will create a new module.

  • Copy the code below:
Sub ExcelToCSV()
Dim rng, row, cell As Range
Dim dqt, dlim, text As String
Dim file As Variant
On Error Resume Next
If ActiveWindow.RangeSelection.Count > 1 Then
text = ActiveWindow.RangeSelection.AddressLocal
Else
text = ActiveSheet.UsedRange.AddressLocal
End If
Set rng = Application.InputBox("Please select the data range:", "ExcelDemy.Com", text, , , , , 8)
If rng Is Nothing Then Exit Sub
file = Application.GetSaveAsFilename("", "CSV File (*.csv), *.csv")
dlim = Application.International(xlListSeparator)
Open file For Output As #1
For Each row In rng.rows
dqt = ""
For Each cell In row.Cells
dqt = dqt & """" & cell.Value & """" & dlim
Next
While Right(dqt, 1) = dlim
dqt = Left(dqt, Len(dqt) - 1)
Wend
Print #1, dqt
Next
Close #1
If Err = 0 Then MsgBox "The CSV file has been saved to: " & file, vbInformation, "ExcelDemy.Com"
End Sub
  • Paste the copied code onto the module.

Excel to CSV with Double Quotes Using VBA

  • Press F5 to run the code.
  • This will ask for your desired range. Toggle back to the worksheet and select the range.
  • Press OK. This will take you directly to the Save As window.

  • Browse the location for the file and enter a name. Click on Save.

  • Excel will show the following message. Press OK.

  • You can check the file.


Explanation of the VBA Code

Sub ExcelToCSV()
We will write the code inside this subject procedure.

Dim rng, row, cell As Range
Dim dqt, dlim, text As String
Dim file As Variant
Declaring necessary variables.

On Error Resume Next
Neglects any errors.

If ActiveWindow.RangeSelection.Count > 1 Then
text = ActiveWindow.RangeSelection.AddressLocal
Else
text = ActiveSheet.UsedRange.AddressLocal
End If
Automatically detects the data to select.

Set rng = Application.InputBox(“Please select the data range:”, “ExcelDemy.Com”, text, , , , , 8)
Asks for the data range.

If rng Is Nothing Then Exit Sub
Exits operation for no input.

file = Application.GetSaveAsFilename(“”, “CSV File (*.csv), *.csv”)
Sets the format of the new file.

dlim = Application.International(xlListSeparator)
Specifies comma as the delimiter.

Open file For Output As #1
Creates a new file.

For Each row In rng.rows
dqt = “”
For Each cell In row.Cells
dqt = dqt & “””” & cell.Value & “””” & dlim
Next
While Right(dqt, 1) = dlim
dqt = Left(dqt, Len(dqt) – 1)
Wend
Print #1, dqt
Next
Close #1
Wraps the cell values with double quotes and populates the new file with them.

If Err = 0 Then MsgBox “The CSV file has been saved to: ” & file, vbInformation, “ExcelDemy.Com”
Confirms saving the CSV file.

Read More: How to Convert Multiple Excel Files to CSV


Things to Remember

  • You need to give the proper file path in the PowerShell command in case you open it from other locations.
  • You need to change the file names based on your files.

Download Practice Workbook


Related Articles

<< Go Back to Export Excel to CSV | Export Data from Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Md. Shamim Reza
Md. Shamim Reza

Md. Shamim Reza, a marine engineer with expertise in Excel and a fervent interest in VBA programming, sees programming as a time-saving tool for data manipulation, file handling, and internet interaction. His diverse skill set encompasses Rhino3D, Maxsurf C++, AutoCAD, Deep Neural Networks, and Machine Learning. He holds a B.Sc in Naval Architecture & Marine Engineering from BUET and has transitioned into a content developer role, generating technical content focused on Excel and VBA. Beyond his professional pursuits,... Read Full Bio

8 Comments
  1. God bless you!

    The 3rd way (using VBA) is just PERFECT.

    Saved me a lot of time.

    Thank you very much.

  2. Thank you very much! Saved me a lot of time, I used the VBA code like a charm.

  3. Tried the 1st way but the numbers became integer, how can I keep the decimals places?

    Also, can I make the double quotes not visible in each cell when open in Excel but they’re there only when open in notepad?

    Thank you.

    • Hey there, Mr. Connie!
      Glad that you have shared you problem here.
      You can keep the decimal places with the number by using the format below.
      “#,##0.00”;“@” (Copy and Paste this)
      But this will add double quotes at each cells of the dataset in Excel.

      You have to use VBA macros to make the double quotes not visible in each cell when open in Excel but they’re there only when open in notepad.

      Regards
      ExcelDemy Team

  4. Hello, is this possible to do with selected cells only?

    • Reply Mahfuza Anika Era
      Mahfuza Anika Era Feb 29, 2024 at 1:36 PM

      Hello TERRY,
      Thank you for your comment. Yes, this is possible to do with selected cells only. To do this, you can use the third method, which is using a VBA code.
      First, you have to select the cells. Then go to the Developer tab >> Visual Basic.

      Then, run the VBA code that is provided in method 3.

      A dialog box will appear, showing the selected cell range. Now, save the file by following the given instructions in method 3.
      Open the file with Notepad or Wordpad, and you will see, the selected cells are only saved with double quotes.

      Regards
      Mahfuza Anika Era
      ExcelDemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo