Handling of Date values can become very annoying. Especially, if Excel always thinks it knows better than the programmer or user *sigh*! Automation is meant to help people, not mess up their work.
In order to help me at least displaying date values in the correct format I implemented a little function to get a pattern string based on a users system locale settings.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
' @Author - Alexander Bolte' @Change Date - 2013-12-14' @Description - Determines the date format of the system the application is running on.' The Excel application is getting the date seperator and the format of date values' from the systems locale settings.' @Returns - A String holding literals for Day (dd), Month (mm) and Year (yyyy)' in the order corresponding the systems locale setting separated using the locales date separator.FunctiongetDateFormat()AsStringDimdateFormatAsStringDimdatOrderAsIntegerDimdatSeparatorAsStringOnErrorGoToerr_handler:datOrder=Application.International(xlDateOrder)datSeparator=Application.International(xlDateSeparator)IfdatOrder=0ThendateFormat="mm"&datSeparator&"dd"&datSeparator&"yyyy"ElseIfdatOrder=1ThendateFormat="dd"&datSeparator&"mm"&datSeparator&"yyyy"ElseIfdatOrder=2ThendateFormat="yyyy"&datSeparator&"mm"&datSeparator&"dd"EndIferr_handler:IfErr.Number<>0ThenErr.ClearEndIfgetDateFormat=dateFormatEndFunction