Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default excel save as csv quotation mark

Hi, I am trying to save a single worksheet from .xls to .csv format. The
worksheet contains dates, strings and numbers.

I would like to open the .csv file in wordpad and have quotation around
the strings. However, the trouble arises when I saved the .xls to .csv
format,
1.without using quotations (before saving) would produce a results of no
quotations
2.with quotations around the strings (before saving) would produce a result
of triple quotation marks.

My eventual goal is to simply have a single quotation mark around the
string, and dates (not the numbers). What can I do?

Thank you for your time,
Brian

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default excel save as csv quotation mark

The secret is to use CHR(34) in place of the double quotes. try this code.
Youprobabbly havve to adjust the range of cells you want to send. This code
is using the activecell current region which end at blank rows and blank
columns.


Sub Gettext()

Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const MyPath = "C:\temp\"
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0


Set fswrite = CreateObject("Scripting.FileSystemObject")

WriteFileName = "quotetext.csv"


'open files
WritePathName = MyPath + WriteFileName
fswrite.CreateTextFile WritePathName
Set fwrite = fswrite.GetFile(WritePathName)
Set tswrite = fwrite.OpenAsTextStream(ForWriting, TristateUseDefault)


MyRows = ActiveCell.CurrentRegion.Rows.Count
Set RowRange = Range(Cells(1, "A"), Cells(MyRows, "A"))

For Each rowcell In RowRange

Lastcol = Cells(rowcell.Row, Columns.Count).End(xlToLeft).Column
ColRange = Range(Cells(rowcell.Row, "A"), Cells(rowcell.Row, Lastcol))
Outline = ""
For Each colcell In ColRange
If Len(Outputline) = 0 Then
Outputline = CStr(colcell)
Else
Outputline = Outputline & "," & CStr(colcell)
End If
Next colcell

tswrite.writeline Chr(34) & Outputline & Chr(34)
Next rowcell
tswrite.Close

Exit Sub
End Sub

"Briankwei1234567" wrote:

Hi, I am trying to save a single worksheet from .xls to .csv format. The
worksheet contains dates, strings and numbers.

I would like to open the .csv file in wordpad and have quotation around
the strings. However, the trouble arises when I saved the .xls to .csv
format,
1.without using quotations (before saving) would produce a results of no
quotations
2.with quotations around the strings (before saving) would produce a result
of triple quotation marks.

My eventual goal is to simply have a single quotation mark around the
string, and dates (not the numbers). What can I do?

Thank you for your time,
Brian

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
Save Excel file to CSV with quotation mark data delimeter? Eric Excel Discussion (Misc queries) 2 December 9th 08 04:05 PM
Single Quotation mark in CSV hon123456 Excel Discussion (Misc queries) 1 November 29th 08 07:49 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
chr() for quotation mark Todd Huttenstine Excel Programming 7 July 29th 04 08:14 PM


All times are GMT +1. The time now is 02:59 AM.

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

About Us

"It's about Microsoft Excel"