Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,670
Default Save Excel file to CSV with quotation mark data delimeter?

I exported an MSACCESS 2007 based query to Excel 2007 and then within excel
save to other format and save to CSV. The problem is that the CSV file is
saved without the quotation marks. I need this data delimeter. Does anyone
has any suggestions on how this can be done? Thanks much!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Save Excel file to CSV with quotation mark data delimeter?

You can use the macro below. change MyPath and WritefileName as required.

Sub WriteCSV()
Const MyPath = "C:\temp\"
Const WriteFileName = "text.csv"

Const Delimiter = ","
DQuote =
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

DQuote = chr(34)

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 = DQuote & Cells(RowCount, ColCount) & DQuote
Else
OutputLine = OutputLine & Delimiter & _
DQuote & Cells(RowCount, ColCount) & DQuote
End If
Next ColCount
OutputLine = OutputLine & ","
tswrite.writeline OutputLine
Next RowCount

tswrite.Close

Exit Sub
End Sub


"Eric" wrote:

I exported an MSACCESS 2007 based query to Excel 2007 and then within excel
save to other format and save to CSV. The problem is that the CSV file is
saved without the quotation marks. I need this data delimeter. Does anyone
has any suggestions on how this can be done? Thanks much!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,670
Default Save Excel file to CSV with quotation mark data delimeter?

Thanks much, it works juts fine - that is exactly what I needed.


"Eric" wrote:

I exported an MSACCESS 2007 based query to Excel 2007 and then within excel
save to other format and save to CSV. The problem is that the CSV file is
saved without the quotation marks. I need this data delimeter. Does anyone
has any suggestions on how this can be done? Thanks much!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Single quotation mark in Excel not showing up PALady Excel Discussion (Misc queries) 2 April 3rd 23 04:36 PM
Single Quotation mark in CSV hon123456 Excel Discussion (Misc queries) 1 November 29th 08 07:49 AM
Single Quotation mark in CSV hon123456 Excel Discussion (Misc queries) 0 November 29th 08 05:15 AM
Excel CSV file: How to preserve double quotation mark on Unix ftp? Shannona Excel Discussion (Misc queries) 2 October 3rd 06 07:54 PM
all data begins with a quotation or apostrohe mark GlennO Excel Discussion (Misc queries) 0 September 27th 06 02:34 PM


All times are GMT +1. The time now is 03:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"