Thread: file formats
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
joel joel is offline
external usenet poster
 
Posts: 9,101
Default file formats

Use filescripting method for reading and writing shown below. The Open #1
method is creating the double quotes in your file.


Sub removedouble()

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


Set fsread = CreateObject("Scripting.FileSystemObject")
Set fswrite = CreateObject("Scripting.FileSystemObject")

ReadFileName = "test.csv"
WriteFileName = "outtest.csv"


'open files
ReadPathName = MyPath + ReadFileName
Set fread = fsread.GetFile(ReadPathName)
Set tsread = fread.OpenAsTextStream(ForReading, TristateUseDefault)

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

Do While tsread.atendofstream = False

InputLine = tsread.Readline

OutputLine = Replace(InputLine, Chr(34) & Chr(34), Chr(34))
If Left(OutputLine, 1) = Chr(34) Then
OutputLine = Mid(OutputLine, 2)
End If
If Right(OutputLine, 1) = Chr(34) Then
OutputLine = Left(OutputLine, Len(OutputLine) - 1)
End If

tswrite.writeline OutputLine
Loop


tswrite.Close
tsread.Close


End Sub


"Richer" wrote:

I have a (.txt) file in notepad that has errors in it. I need to correct the
errors in excel and then save it back to the exact (.txt) format. I am using
Excel 2003 and I am having difficulties trying to accomplish this task.
Example: original file
"cellcontent1","cellcontent2","cellcontent3","cell content4",

Example: after corrections and saving back to (.txt)
""cellcontent1"",""cellcontent2"",""cellcontent3"" ,""cellcontent4"", -
[double qoutes]

or
" cellcontent1 ",'" cellcontent2 ", - [space on each
side cell content]

I must be missing a step somewhere - can someone help identify my missing
step?
--
Richer