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

This article illustrates 3 simple ways to convert excel files to save as CSV with double-quotes. Saving CSV files with double quotes is necessary to avoid any misrepresentation of the data. 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 more befitting. The following picture highlights the purpose of this article. Have a quick look through it to learn how to do that.

excel save csv with double quotes


Save Excel as CSV with Double Quotes: 3 Quickest Ways

1. Use Custom Format to Save Excel as CSV with Double Quotes

Imagine you have the following dataset. You want to save it as a CSV file with cell values wrapped in double-quotes. Then follow the steps below.

📌 Steps

  • First, select the entire range (A1:B6) of the dataset.
  • Then, press CTRL+1 to open the Format Cells window.
  • Next, select the Custom format from the Number tab.
  • Then, enter \“#\”;\“@\” in the Type field.
  • After that, press OK.

Excel to CSV with Double Quotes Using Custom Format

  • Next, select File >> Save As. Then browse the desired location to save the file.
  • After that, enter a file name. Now, choose CSV (Comma delimited) (*.csv) as the file type using the dropdown arrow.
  • Then, click on the Save button.

  • Next, go to that desired location. Then open the CSV file with a text editor (Notepad etc).

  • After that, you will see the following result containing some extra double-quotes.

  • Now, 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.
  • Finally, you will get the desired result as follows.

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


2. Use Windows PowerShell

Alternatively, you can save the CSV file without double quotes first. Then, you can add double quotes using Windows Powershell. Follow the steps below to be able to do that.

📌 Steps

  • First, go to the worksheet that you want to save as a CSV file.
  • Next, select File >> Save As as in the earlier method.
  • Then, browse the desired location for the file. Next, enter a name for the file.
  • After that, choose CSV (Comma delimited) (*.csv) as the file type using the dropdown arrow.
  • Then, click on the Save button.

Covert Excel files and save as CSV files

  • After that, you will get the following result.

  • Now, hold the SHIFT key and right-click on any blank space in the location of the CSV file without double-quotes.
  • Then, click on the Open PowerShell window here.

  • Now, copy the following command. You need to change the file names based on your files.
import-csv Sales1.csv | export-csv Sales2.csv  -NoTypeInformation -Encoding UTF8
  • Then, paste the copied code onto the PowerShell window and press Enter.

Excel to CSV with Double Quotes Using Windows PowerShell

  • After that, you will get the desired result as shown in the picture below.

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


3. Apply a VBA Code for CSV File with Double Quotes

You can also use Excel VBA to get the same result. Follow the steps below to do that.

📌 Steps

  • First, press ALT+F11 to open the VBA window.
  • Then, select Insert >> Module as shown in the following picture. This will create a new module.

  • Now, copy the code below, using the copy button.
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
  • Then, paste the copied code onto the module as shown below.

Excel to CSV with Double Quotes Using VBA

  • Next, press F5 to run the code. This will ask for your desired range. Now, you can toggle back to the worksheet and select the range. Then, press OK. This will take you directly to the Save As window.

  • Now, browse the location for the file and enter a name. Then, click on Save.

  • After that, excel will show the following message.

  • Finally, you can check for the following results.


🔎 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


Conclusion

Now you know how to convert excel files to save as CSV files with double-quotes. Please let us know if this article has provided you with your desired solution. You can also use the comment section below for further queries or suggestions. Do visit our ExcelDemy blog to learn more about excel. Stay with us and keep learning.


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