Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Date format problem on export to CSV

Hi, I am running a macro to export an xls file to csv. The xls contains dates
formatted as dd/mm/yyyy. However, when the 'save as' code is executed the
format is lost. The csv file contains mm/dd/yyyy. Any ideas how to retain the
european format so I get dd/mm/yyyy in my csv?
I have checked my regional settings and have dd/mm/yyyy enabled.
I have seen threads for the reverse issue (csv into xls) but have idea how
to fix the issue of xls to csv.
I am using Office Excel 2003 SP1 if this makes a difference.

Any help would be appreciated.
Many Thanks, Nijk
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Date format problem on export to CSV

Having a US English version, it isn't something I have a lot of experience
with, but if nothing else, you can write the file with code. A start is to
use Chip Pearson's code and modify it to work with your dates.

http://www.cpearson.com/excel/imptext.htm import/export text files

--
Regards,
Tom Ogilvy


"Nijk" wrote in message
...
Hi, I am running a macro to export an xls file to csv. The xls contains

dates
formatted as dd/mm/yyyy. However, when the 'save as' code is executed the
format is lost. The csv file contains mm/dd/yyyy. Any ideas how to retain

the
european format so I get dd/mm/yyyy in my csv?
I have checked my regional settings and have dd/mm/yyyy enabled.
I have seen threads for the reverse issue (csv into xls) but have idea how
to fix the issue of xls to csv.
I am using Office Excel 2003 SP1 if this makes a difference.

Any help would be appreciated.
Many Thanks, Nijk



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Date format problem on export to CSV

Hi Tom,
Thanks for the really quick response and suggestion. I checked out Chip's
code but actually it was not necessary to go this far.
The problem was solved by a colleague of mine (thanks to Andy M.) with some
clever lateral thinking. Since Excel VBA converts the dates to US format on
the save he swapped the date format in the source file before the VBA save.
Excel was fooled into putting the date format back into European format. Here
is the code:
========================================
' The extra line required to fool excel is...
Worksheets("Sheet1").Columns(2).NumberFormat = "dd/mm/yyyy"

' Then Save the file as csv
ActiveWorkbook.SaveAs Filename:= _
"C:\AnyDir\"Filename.csv", FileFormat:=xlCSV, CreateBackup:=False
===================================
Works like a dream and very simple...
Regards
Nijk

"Tom Ogilvy" wrote:

Having a US English version, it isn't something I have a lot of experience
with, but if nothing else, you can write the file with code. A start is to
use Chip Pearson's code and modify it to work with your dates.

http://www.cpearson.com/excel/imptext.htm import/export text files

--
Regards,
Tom Ogilvy


"Nijk" wrote in message
...
Hi, I am running a macro to export an xls file to csv. The xls contains

dates
formatted as dd/mm/yyyy. However, when the 'save as' code is executed the
format is lost. The csv file contains mm/dd/yyyy. Any ideas how to retain

the
european format so I get dd/mm/yyyy in my csv?
I have checked my regional settings and have dd/mm/yyyy enabled.
I have seen threads for the reverse issue (csv into xls) but have no idea how
to fix the issue of xls to csv.
I am using Office Excel 2003 SP1 if this makes a difference.

Any help would be appreciated.
Many Thanks, Nijk




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 Format Problem - Date Overrides Format Mary Excel Discussion (Misc queries) 5 February 10th 10 05:49 AM
Date Format Problem (bug) Steve - Rabbit Man Excel Discussion (Misc queries) 5 October 31st 09 01:43 AM
Date Format Problem Gayla Excel Discussion (Misc queries) 3 April 18th 07 07:48 PM
Date Format Problem Jason Excel Programming 1 May 17th 05 06:46 PM
VBA export excel to .txt, number format problem Dave Peterson[_5_] Excel Programming 0 November 23rd 04 08:27 PM


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