LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default saving in CSV with a nonstandard list separator - possible bug or 'bydesign' quirkness ?

I've been trying to save an excel workbook in CSV format, using a
semicolon instead of a colon as field separator.
The MSDN docs, more or less, state that via VBA/Ole Automation a comma
is always used, unless the Local parameter of the Workbook.SaveAs
method is set to True. In this case the Control Panel/Internation
Settings for the list separator should be used. I've built a very
simple VB6 sample application, using Excel 2003 (11.0 version type
library). All I do is open excel, add a workbook (creating a Workbook
object), write into a couple of cells, and then try to save the file
in CSV format (using the Workbook.SaveAs method). Then I duly
WorkBook.Close the Workbook and Excel.Quit MS Excel. I've been
getting always commas, the locale setting seemed to be always ignored.
A quick google search resulted about the problem confirmed that a lot
of other people had the same situation, but there was no solution. I
seem to have found, however, that the WorkBook.Close method,
unexplainedly, seems to perform a second Save on the file, this time
ignoring the locale settings and overwriting the first .SaveAs, which
is performed using the correct locale settings... Using Workbook.Close
false or avoiding a .Close altogether seems to bypass problems. When
Workbook.Close is not used, Excel.Quit forces another save, but this
time the locale settings are retained !!


Private Sub Command1_Click()

Dim Excel As Object

Set Excel = CreateObject("Excel.application")
Dim Workbook As Excel.Workbook
Set Workbook = Excel.Workbooks.Add

Workbook.Activate
Excel.Visible = True
Dim Worksheet As Object
Set Worksheet = Workbook.ActiveSheet


Worksheet.Rows.Cells(1, 1) = 3.14159265
Worksheet.Rows.Cells(1, 2) = 2.71828183

'xlCSV = 6
'Local := True forces excel to use control panel settings for the list
separator
Workbook.SaveAs "C:\testcsv.txt", 6, Local:=True

'if this line is commented, the file is saved a second time, WITHOUT
control panel settings
'avoiding to close explicitly the workbook and quitting excel directly
forces another save
'but this time control panel settings are used!
Workbook.Close

Excel.Quit
End Sub
 
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
list separator widman Excel Discussion (Misc queries) 3 November 5th 07 03:12 PM
List Separator Kieran H Excel Programming 9 March 8th 07 12:59 PM
list separator Kieran H Excel Programming 1 February 26th 07 07:00 AM
Saving a worksheet to csv with different separator bazza1 Excel Worksheet Functions 3 September 16th 06 09:03 PM
list separator settings culkebas Excel Discussion (Misc queries) 2 December 22nd 05 08:26 AM


All times are GMT +1. The time now is 08:05 AM.

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

About Us

"It's about Microsoft Excel"