A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Save Excel file to CSV with quotation mark data delimeter?



 
 
Thread Tools Display Modes
  #1  
Old December 9th, 2008, 02:03 PM posted to microsoft.public.excel.misc
Eric
external usenet poster
 
Posts: 1,956
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  
Old December 9th, 2008, 02:15 PM posted to microsoft.public.excel.misc
Joel
external usenet poster
 
Posts: 2,855
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  
Old December 9th, 2008, 04:05 PM posted to microsoft.public.excel.misc
Eric
external usenet poster
 
Posts: 1,956
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!

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:23 AM.


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