+ Reply to Thread
Results 1 to 4 of 4

Date format problem on export to CSV

  1. #1
    Nijk
    Guest

    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. #2
    Tom Ogilvy
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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. #3
    Nijk
    Guest

    Re: 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" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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

    >
    >
    >


  4. #4
    Registered User
    Join Date
    08-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Date format problem on export to CSV

    This is a very late reply. Solution is to reformat the dates as text before exporting.

    TEXT(date,"dd/mm/yyyy")

    This exports perfectly

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1