Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Export to CSV via macro does not use local regional settings

Hi,

I try to export my data from Excel 2003 to a CSV file. I use "German/
Deutsch" regional settings (so a semicolon ";" is my list separator)
but changed the decimal point and group character to be "." for
decimal point and "," for group as in English/US regional settings. I
need to do this, to import the data in an ORACLE database. When doing
a Save-As from the menu this works, but not in a macro.

I found the postings about using "Local:=true" as additional parameter
for SaveAs method. But still no luck. Excel ignores this and still
exports using a comma "," as the field delimiter.

Any idea what goes wrong?

TIA,
Stefan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Export to CSV via macro does not use local regional settings

If you don't get a better solution, the macro below wil create your file.
Just change the delimiter to what ever you need

Sub WriteCSV()

Const MyPath = "C:\temp\"
Const WriteFileName = "text.csv"

Const Delimiter = ","

Const ForReading = 1, ForWriting = 2, ForAppending = 3

Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

Set fswrite = CreateObject("Scripting.FileSystemObject")

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

LastRow = Cells(Rows.Count, "A").End(xlUp).Row

For RowCount = 1 To LastRow
LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Column
For ColCount = 1 To LastCol
If ColCount = 1 Then
OutPutLine = Cells(RowCount, ColCount)
Else
OutPutLine = OutPutLine & Delimiter & Cells(RowCount, ColCount)
End If
Next ColCount
tswrite.writeline OutPutLine
Next RowCount

tswrite.Close

End Sub


"Stefan" wrote:

Hi,

I try to export my data from Excel 2003 to a CSV file. I use "German/
Deutsch" regional settings (so a semicolon ";" is my list separator)
but changed the decimal point and group character to be "." for
decimal point and "," for group as in English/US regional settings. I
need to do this, to import the data in an ORACLE database. When doing
a Save-As from the menu this works, but not in a macro.

I found the postings about using "Local:=true" as additional parameter
for SaveAs method. But still no luck. Excel ignores this and still
exports using a comma "," as the field delimiter.

Any idea what goes wrong?

TIA,
Stefan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Export to CSV via macro does not use local regional settings

Joel,

thanks for providing your solution. I already found it as answer to
another post regarding the same problem. I did not use it, as I still
thought I made something wrong. But now on a second thought I
integrated it, as it gives me more control of what gets exported.

Thanks again,
Stefan


On 1 Feb., 17:15, Joel wrote:
If you don't get a better solution, the macro below wil create your file. *
Just change the delimiter to what ever you need

Sub WriteCSV()

Const MyPath = "C:\temp\"
Const WriteFileName = "text.csv"

Const Delimiter = ","

Const ForReading = 1, ForWriting = 2, ForAppending = 3

Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

Set fswrite = CreateObject("Scripting.FileSystemObject")

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

* *LastRow = Cells(Rows.Count, "A").End(xlUp).Row

* *For RowCount = 1 To LastRow
* * * LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Column
* * * For ColCount = 1 To LastCol
* * * * *If ColCount = 1 Then
* * * * * * OutPutLine = Cells(RowCount, ColCount)
* * * * *Else
* * * * * * OutPutLine = OutPutLine & Delimiter & Cells(RowCount, ColCount)
* * * * *End If
* * * Next ColCount
* * * tswrite.writeline OutPutLine
* *Next RowCount

* *tswrite.Close

End Sub



"Stefan" wrote:
Hi,


I try to export my data from Excel 2003 to a CSV file. I use "German/
Deutsch" regional settings (so a semicolon ";" is my list separator)
but changed the decimal point and group character to be "." for
decimal point and "," for group as in English/US regional settings. I
need to do this, to import the data in an ORACLE database. When doing
a Save-As from the menu this works, but not in a macro.


I found the postings about using "Local:=true" as additional parameter
for SaveAs method. But still no luck. Excel ignores this and still
exports using a comma "," as the field delimiter.


Any idea what goes wrong?


TIA,
Stefan- Zitierten Text ausblenden -


- Zitierten Text anzeigen -


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 not using regional settings Dweezil38 Excel Discussion (Misc queries) 6 March 15th 11 08:50 AM
Regional settings Ana via OfficeKB.com Excel Worksheet Functions 1 October 27th 09 02:41 PM
regional settings Spike Excel Worksheet Functions 5 July 29th 07 01:10 AM
Regional Settings LAF Excel Discussion (Misc queries) 2 July 30th 05 12:51 PM
Put one of the Regional Settings in a variable holysoul[_6_] Excel Programming 2 June 10th 04 01:37 PM


All times are GMT +1. The time now is 10:14 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"