![]() |
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, |
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, |
All times are GMT +1. The time now is 02:53 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com