View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Help?[_2_] Help?[_2_] is offline
external usenet poster
 
Posts: 40
Default Quotes in CSV Files

JMB,
I can't seem to get this to work properly. However, I have an idea but do
not know how to accomplish with a macro. Could I take the header information,
keep it in word or notepad and have an excel macro write the xlcsv to that
template? If so how would I do that?

"JMB" wrote:

This appeared to work. I've found TextStreamObjects will write the data to
file w/o enclosing it in quotes. You'll need to test to see if it works for
what you are doing. You will need to set up a reference to the Scripting
library (Tools/References - Microsoft Scripting Runtime). Change strFileIn
and out for your filenames.

To check, I changed the extension on the CSVClean file to .txt so it would
open in Notepad. I'm sure you know that if you open the cleaned file in
Excel, the (,) will split the data into two columns.

Sub test2()
Const strFileIn As String = "I:\Excel\CSVData.csv"
Const strFileOut As String = "I:\Excel\CSVClean.csv"
Dim FSO As Scripting.FileSystemObject
Dim fDest As Scripting.TextStream
Dim strData As String
Dim lngFNum1 As Long

Set FSO = New Scripting.FileSystemObject
Set fDest = FSO.CreateTextFile(strFileOut, True)

lngFNum1 = FreeFile()
Open strFileIn For Input As #lngFNum1

Do While Not EOF(lngFNum1)
Line Input #lngFNum1, strData
strData = Replace(strData, """", "", 1, -1, vbTextCompare)
fDest.WriteLine strData
Loop

Close
fDest.Close

End Sub


"Help?" wrote:

I am trying to find a macro that will force the "" around the below to not
happen. Because the below has a comma in it, on csv convertion it
automatically insert the "". Can I force this through VBA macro to not do
this? This will be the third time I have asked for help, but not received
yet. Can anyone help me in this?

Coming out as:

"%!
XGF
9999 SETBUFSIZE
(,) SETDBSEP
QSTRIP_on
(GuntherIPEP.jdt) SETJDT
(IPEP.dbm) STARTDBM"


I need it to be:

%!
XGF
9999 SETBUFSIZE
(,) SETDBSEP
QSTRIP_on
(GuntherIPEP.jdt) SETJDT
(IPEP.dbm) STARTDBM