Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Quotes and CSV files
When saving a CSV file and a cell contains quotes, Excel adds more quotes -
I guess this is the CSV standard. For example, if cells A1:A3 are "test" "" Test then Excel will save as ""test"","""",Test I want to save like this "test","",Test Anyone? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Quotes and CSV files
Tr this macro
Sub WriteCSV() Const MyPath = "C:\temp\" Const WriteFileName = "text.csv" Const Delimiter = "," Const ForReading = 1, ForWriting = 2, ForAppending = 3 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 Set fswrite = CreateObject("Scripting.FileSystemObject") 'open files WritePathName = MyPath + WriteFileName fswrite.CreateTextFile WritePathName Set fwrite = fswrite.GetFile(WritePathName) Set tswrite = fwrite.OpenAsTextStream(ForWriting, TristateUseDefault) LastRow = Cells(Rows.Count, "A").End(xlUp).Row For RowCount = 1 To LastRow LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Column For ColCount = 1 To LastCol If ColCount = 1 Then OutputLine = "," & Cells(RowCount, ColCount) Else OutputLine = OutputLine & Delimiter & Cells(RowCount, ColCount) End If Next ColCount OutputLine = OutputLine & "," tswrite.writeline OutputLine Next RowCount tswrite.Close End Sub "PM" wrote: When saving a CSV file and a cell contains quotes, Excel adds more quotes - I guess this is the CSV standard. For example, if cells A1:A3 are "test" "" Test then Excel will save as ""test"","""",Test I want to save like this "test","",Test Anyone? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Quotes and CSV files
Joel wrote:
Tr this macro Sub WriteCSV() Const MyPath = "C:\temp\" Const WriteFileName = "text.csv" Const Delimiter = "," Const ForReading = 1, ForWriting = 2, ForAppending = 3 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 Set fswrite = CreateObject("Scripting.FileSystemObject") 'open files WritePathName = MyPath + WriteFileName fswrite.CreateTextFile WritePathName Set fwrite = fswrite.GetFile(WritePathName) Set tswrite = fwrite.OpenAsTextStream(ForWriting, TristateUseDefault) LastRow = Cells(Rows.Count, "A").End(xlUp).Row For RowCount = 1 To LastRow LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Column For ColCount = 1 To LastCol If ColCount = 1 Then OutputLine = "," & Cells(RowCount, ColCount) Else OutputLine = OutputLine & Delimiter & Cells(RowCount, ColCount) End If Next ColCount OutputLine = OutputLine & "," tswrite.writeline OutputLine Next RowCount tswrite.Close End Sub Thanks Joel, I will give that a go. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel puts quotes around cells with commas in tab delimited files | Setting up and Configuration of Excel | |||
change straight quotes to curly quotes | Excel Discussion (Misc queries) | |||
Quotes in CSV Files | Excel Programming | |||
How do I output csv files from Excel with quotes round text fields | Excel Discussion (Misc queries) | |||
How do i get historical stock quotes using MSN Money Stock Quotes | Excel Discussion (Misc queries) |