View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default date format in CSV

I assume the data inside the file is incorrect and note the filename itself.
I just want to make sure that when you are using MyValue you are not creating
the date and this is your problem

First, there are lots of problems with the CSV read and write functions in
excel. there do all sorts of data translations that people do not want. In
your case, it is taking a date format and converting it to some unwanted
international standard. Excel releases in different countries to all sorts
of unexpected modifications. You may want to try going into Tool - Options
and change some of the internation options or some other option to see if
this fixes the problem.

I'm working in New Jersey (USA) tonight from 11:00 PM - 7:00 AM (I gues that
would be 8 hours difference in Israel 7:00AM - 3:00PM). If you need
additional help let me know. The other option is to save your file manually.
Here is an example of saving CSV format manually.

Sub putcsv()
Const myFileName = "c:\temp\myfile.csv"
Const ForReading = 1, ForWriting = 2, _
ForAppending = 3

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateTextFile _
(myFileName, True)

Lastrow = Range("A" & Rows.Count).End(xlUp).Row

For RowCount = 1 To Lastrow

outputline = ""
Lastcol = Cells(RowCount, Columns.Count).End(xlToLeft).Columns
If Lastcol 0 Then
Do While (Lastcol = 1) And _
IsEmpty(Cells(RowCount, Lastcol))

Lastcol = Lastcol - 1
Loop

For Colcount = 1 To Lastcol
If Colcount = 1 Then
outputline = Cells(RowCount, Colcount)
Else
outputline = outputline & "," & _
Cells(RowCount, Colcount)
End If
Next Colcount
End If
f.writeline outputline
Next RowCount
f.Close
End Sub


"Helmut" wrote:

Joel,
I opened the newly create csv file in NOTEPAD and format was 4,30,2008 which
is incorrect. ON SCREEN before FILESAVEAS the correct format: 30/04/2008
appears.
So it seems there is a problem with this:
ActiveWorkbook.SaveAs
Filename:="\\shekel-srv\public\Personel\2008\ToCAV" & Left(Myvalue, 2) &_
Right(Myvalue, 2) & "m.csv", FileFormat:=xlCSV

Can you help?
thanks
Helmut



"Joel" wrote:

Lets see if the problem is with writing or reading the file. Try opening the
CSV file with Notepad and see what the data looks like. Then we will know
where the problem is located.

"Helmut" wrote:

I have the following:

Range("Q1").Select
Selection.NumberFormat = "dd/mm/yyyy"

later I have this:
Range("Q1").Select
ActiveCell.FormulaR1C1 = "=EOMONTH(R1C19,0)"

The date appears correctly in the cell as i.e. "30/04/2008"

If I manually save now as test.csv file, it saves it correctly and when I
open the cell is correct.
HOWEVER
Further in the macro I have this:

ActiveWorkbook.SaveAs
Filename:="\\shekel-srv\public\Personel\2008\ToCAV" & Left(Myvalue, 2) &
Right(Myvalue, 2) & "m.csv", FileFormat:=xlCSV

When I open this file: "ToCAV0408m.csv" the cell appears: "04/30/2008"

I just cant figure out why it changes the cell content. HELP please.