View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Rafael Rafael is offline
external usenet poster
 
Posts: 24
Default Saving in text format: why are there ""?

Actually the link that Tom gave me was really helpfull: I adapted the
following code to my program and this was the best was I found to convert
excel data into a text format:

Public Sub ExportToTextFile(FName As String, _
Sep As String, SelectionOnly As Boolean)

Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer
Dim CellValue As String


Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile

If SelectionOnly = True Then
With Selection
StartRow = .Cells(1).row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).row
EndCol = .Cells(.Cells.Count).Column
End With
Else
With ActiveSheet.UsedRange
StartRow = .Cells(1).row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).row
EndCol = .Cells(.Cells.Count).Column
End With
End If

Open FName For Output Access Write As #FNum

For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
If Cells(RowNdx, ColNdx).Value = "" Then
CellValue = Chr(34) & Chr(34)
Else
CellValue = Cells(RowNdx,ColNdx).Text
End If
WholeLine = WholeLine & CellValue & Sep
Next ColNdx
WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
Print #FNum, WholeLine
Next RowNdx

EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #FNum

End Sub


"NickHK" wrote:

Rafael,
Post a sample of the data you have and the result you want.

NickHK


"Rafael" ...
How do I remove the situation of delimitation when saving as? how do I
save
as fixed space? (I tried all types of TXT formats and all of them give me
double quotes)

"Tom Ogilvy" wrote:

That usually is the case if you are saving as a delimited file and the
contents of the cell contains the delimiter within. Remove that
situation
and you shouldn't get the double quotes.

Or save the file as fixed space so there are no delimiters.

or you can write code to create the file to fit your specifications.
Here
is a start:
http://www.cpearson.com/excel/imptext.htm import/export text files

--
Regards,
Tom Ogilvy


"Rafael" wrote:

I am trying to save data from an excel spreadsheet under .txt format.
However
the final format has quotes "" at the begining and end of certain
lines. How
do I get rid of them?