Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default How to get excel to export quotes always...

Hi-

I need excel to export ASCII text data with quotes around each field, not
just fields that contain a comma. Our data needs to be shipped to a program
that always expects the quotes.

Excel only puts a quote around a field with a comma in it. I want excel to
do it always?

Thanks,
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default How to get excel to export quotes always...

You need a macro

Sub WriteCSV()
Const myFileName = "c:\temp\myfile.csv"
Const ForReading = 1, ForWriting = 2, _
ForAppending = 3

Set fs = CreateObject("Scripting.FileSystemObject")

FileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Text Files (*.CSV), *.CSV")
If FileSaveName = False Then
MsgBox ("Cannot Get Filename - Exiting Macro")
Exit Sub
End If


Set f = fs.CreateTextFile _
(Filename:=FileSaveName, overwrite:=True)

Lastrow = Range("A" & Rows.Count).End(xlUp).Row

For RowCount = 1 To Lastrow

LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Columns
If LastCol = 1 And _
Range("A" & RowCount) = "" Then
'if row is empty write blank line
f.writeline
Else
OutputLine = ""

For ColCount = 1 To LastCol
If ColCount = 1 Then
OutputLine = Chr(34) & Cells(RowCount, ColCount) & Chr(34)
Else
OutputLine = OutputLine & "," & _
Chr(34) & Cells(RowCount, ColCount) & Chr(34)
End If
Next ColCount
f.writeline OutputLine
End If
Next RowCount
f.Close
End Sub


"Rich DeVito" wrote:

Hi-

I need excel to export ASCII text data with quotes around each field, not
just fields that contain a comma. Our data needs to be shipped to a program
that always expects the quotes.

Excel only puts a quote around a field with a comma in it. I want excel to
do it always?

Thanks,

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
export re-order input fields to export file [csv] madisonpete Excel Worksheet Functions 0 November 30th 07 03:51 PM
change straight quotes to curly quotes callico Excel Discussion (Misc queries) 2 June 22nd 07 10:23 PM
How do i get historical stock quotes using MSN Money Stock Quotes Ash Excel Discussion (Misc queries) 0 May 11th 06 03:26 AM
excel quotes Old Maps Excel Worksheet Functions 3 April 28th 06 04:10 PM
export .CSV with field containing double quotes? William DeLeo Excel Discussion (Misc queries) 5 April 5th 06 06:08 PM


All times are GMT +1. The time now is 08:54 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"