Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Typing a quote character Vs pasting a quote character= what happens to the resulting CSV? Interesting!!

in a CSV file, text with quotes will look like this


,"text center string",

so if the text string originally looked like

text "center" string

then it would appear in the csv as

,"text ""center"" string",

but your routine is not doing this and so it appears as what you call
corrupted.

,"text 'center' string", where the ' represents the pasted quotes, does
not cause a problem because they do not match the text delimiter.

Regards,
Tom Ogilvy


Julian Milano wrote in message
...
XL2000 SP3, 2002, WinXP SP2

I have an application which contains a userform with a textbox. The data

in
the textbox is written to a worksheet where the worksheet is saved as a

CSV
file. I have been experiencing corruption in the CSV file occaisonally,

but
have not been able to find the problem until now and need someone to shed
some light.

The following text has been typed, manually via the keyboard, into the
textbox. This is what is written to the CSV file:

called "magically", but really

The following text has been copied from a Word document, via the cut/paste
facility (CTRL-C & CTRL-V), and pasted into the textbox. This is what is
written to the CSV file:

called "magically", but really

Note two things here. Quotes typed into the textbox will cause the CSV

file
to "corrupt itself", while quotes pasted into an textbox will work fine!
Based on this, note the style of the quote characters above, which are

only
evident when the font is changed to Tahoma.

For those of you who can't see the formatting above, the first block of

text
contains two double-quotes, both are vertical in style, like this: || and
||.
The second block of text contains two double-quotes, both are angled

style,
like this: \\ and //.

Why is this happening?

Here's my CSV writing routine (Why am I not using the standard Save-As CSV
in XL - because my clients in some foreign countries have their regional
settings set so that CSV files are not comma delimited, but semi-colon
delimited!!! And when the resulting CSV file is received by the software

in
a different regional setting, where commas are the default delimiter, the
CSV file appears corrupt) When I say "appears corrupt", I mean that the
cells pasted to create the original CSV, appear in all the wrong places

when
the CSV is received in a different regional setting PC, due to the quotes

in
the text in the cells.

Function WriteFile(ws2Save As Worksheet, CSVFilename As String, _
delimiter As String, quotes As Integer) As String

' Dimension variables to be used in this function.
Dim CurFile As String
'Dim wb2Save
Dim CellText As String
Dim RowNum As Integer
Dim ColNum As Integer
Dim FNum As Integer
Dim TotalRows As Double
Dim TotalCols As Double

FNum = FreeFile()
' Open the selected file name for data output.
Open CSVFilename For Output As #FNum
' Store the total number of rows and columns to variables.
TotalCols = ws2Save.UsedRange.Columns.Count
TotalRows = ws2Save.Range("A65535").End(xlUp).Row
' Loop through every cell, from left to right and top to bottom.
For RowNum = 1 To TotalRows
For ColNum = 1 To TotalCols
With ws2Save.Cells(RowNum, ColNum)
' CellText = PreProcessText(.Value)
CellText = .Value
End With
' Write the contents to the file.
' With or without quotation marks around the cell information.
Select Case quotes
Case vbYes
CellText = Chr(34) & CellText & Chr(34) & delimiter
Case vbNo
CellText = CellText & delimiter
End Select
Print #FNum, CellText;
' Update the status bar with the progress.
Application.StatusBar = Format((((RowNum - 1) * TotalCols) _
+ ColNum) / (TotalRows * TotalCols), "0%") & " Completed."
' Loop to the next column.
Next ColNum
' Add a linefeed character at the end of each row.
If RowNum < TotalRows Then Print #FNum, ""
' Loop to the next row.
Next RowNum
' Close the .prn file.
Close #FNum
' Reset the status bar.
Application.StatusBar = False
WriteFile = "Exported"
End Function



--


Julian Milano




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
Excel 2007 - Formatting text in cell (character by character) TomC Excel Discussion (Misc queries) 0 January 29th 10 07:25 PM
SELECTING FROM A DROP DOWN LIST BY TYPING FIRST CHARACTER MARGARET KISS New Users to Excel 3 January 9th 08 08:53 PM
Excel-Match 1st text character in a string to a known character? bushlite Excel Worksheet Functions 2 January 15th 07 06:36 PM
typing a complement (i.e. notA) character in Excel jheby Excel Discussion (Misc queries) 6 September 6th 06 12:30 AM
Typing a quote character Vs pasting a quote character= whathappens to the resulting CSV? Interesting!! Jon Peltier[_3_] Excel Programming 0 August 3rd 03 02:22 AM


All times are GMT +1. The time now is 01:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"