By: Lutfor Rahman Shimanto

In reply to Luke.

Hello Luke

Thanks for reaching out and sharing an exciting problem.

You want to generate a comma-delimited (.txt) file from an Excel sheet. When saving as CSV, you want to remove the double quotes that Excel automatically adds. The text file should have each data point separated by commas, without any quotes surrounding the text.

Don’t worry! I have developed an Excel VBA code to help you overcome your situation. Please check the following:

Excel VBA Sub-procedure:

Sub ExcelToTXT()

Dim rng, row, cell As Range
Dim 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(InitialFileName:="", FileFilter:="Text Files (*.txt), *.txt")

dlim = ","

Open file For Output As #1

For Each row In rng.Rows

text = ""
For Each cell In row.Cells
text = text & cell.Value & dlim
Next cell

text = Left(text, Len(text) - Len(dlim))

Print #1, text

Next row

Close #1

If Err = 0 Then MsgBox "The text file has been saved to: " & file, vbInformation, "ExcelDemy.Com"

End Sub

I hope you have found the solution you were looking for. I have attached the solution workbook. Good luck.

DOWNLOAD SOLUTION WORKBOOK

Regards
Lutfor Rahman Shimanto
Excel & VBA Developer
ExcelDemy