Excel Date formats using VBA according to the Regional Settings
To format a date using Excel VBA according to the particular Windows Regional Settings (WRS) or locale you have to specify the date format as follows:-
If you specify the number format suffixing it with the @ at the end, (i.e. "m/d/yy;@") then the format ignores the regional settings and hard codes the date format as specified. There are at least two other functions that also allow you to define a date in a flexible format according to the locale settings:-
FormatDateTime - Formats date according to the long or short date/time format of the PC
DateSerial - Returns a Variant (Date) for a specified year, month, and day.
If you need to retrieve the values of any windows regional settings you can use the Application.International property. For example to display a message with the windows control panel regional setting from Excel use:-
Using a generic display formats for dates is useful if you're developing applications that are used internationally.
On a different but related note. The best way to stream dates from Java to Excel is to stream them as java.util.Date and then format the dates in Excel. When you stream a util.Date format you're sending a date serial number which avoids any mis-interpretation of dates when Excel tries to be clever and parse the dates for you.
References: Excel 2002 Power Programming with VBA, John Walkenbach
Excel 2007 VBA, John Green, et al.


