Home » excel » Excel Macro date format changing on file open

Excel Macro date format changing on file open

Posted by: admin April 23, 2020 Leave a comment


I have a weird problem, whenever I open my csv file into excel manually, the dates appear correctly formatted in UK locale – dd/mm/yyyy. However, I have a macro which opens up my csv file, and I get some dates formatted in as mm/dd/yyyy and others formatted as dd/mm/yyyy. The pattern seems to be the ones which are incorrect seems to be when the is a single digit for the day so 05/11/2012 is now appearing as 11/05/2012, but 15/11/2012 is appearing exactly as the csv file.

Any help would be great.


Sub openfile()
' openfile Macro

   Workbooks.Open filename:= _
End Sub
How to&Answers:

VBA uses the default local of USA,( even if you are in a diferent locale) with all the formatting set to it(date separators, decimal separators). You can bypass it with the local attribute:

  Call Workbooks.Open(Filename:="c:\myfile.csv", local:=True)