date order changes when opening csv file via macro

Hi,
I have a file that is used everyday. I wrote a macro that deletes the contents of a worksheet and then opens a csv file, copies the data into the worksheet and then closes the csv file.
I work with dates in the dd/mm/yyyy format (Ireland). When the csv file is opened the days 01 to 09 reverse with the month
example 2nd May 2006 02/05/2006 becomes 05/02/2006. - dates 10 - 31 are fine example - 24th May 2006 stays 24/05/2006

If I open the csv file directly with excel the dates are fine. It seems that using the macro upsets it!!! I need to import the csv file via a macro etc.
Anyone got any ideas??

Peter
LVL 1
ptp2Asked:
Who is Participating?
 
dcp002Commented:
Don't OPEN the .CSV file - IMPORT the data instead.

Using Excel 2002 I reproduced your problem with this macro:
    Workbooks.Open Filename:= _
        "C:\Documents and Settings\david\My Documents\book1.csv"
    Columns("A:A").EntireColumn.AutoFit

The following macro worked with dates in English / Irish format:

    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Documents and Settings\david\My Documents\Book1.csv", Destination:= _
        Range("A1"))
        .Name = "Book1"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With

Or if you want to record the macro and change a few options:

Data - Import External Data - Import data.
{select filename}
Delimited - NEXT
comma - NEXT
DMY for date format      - NEXT      <<<<------------------------------------------------ this is what sorts it.
etc.
0
 
junglerover77Commented:
Please go to "Control Panel" -> "Regional and Language Options" and select "English (Ireland)".

Regards,
Jungle
0
 
ptp2Author Commented:
Hi Jungle,

Thanks for your input. My settings are set to English (Ireland) already. The problem only occurs when opening the csv file via a macro.

Regards
Peter

0
 
ptp2Author Commented:
Hi dcp002,

Thanks for help. Sorry about the delay in replying. I took your advise and used the macro route and it worked.

Thanks again
Peter
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.