如何使用excel vba检查OS系统的date格式
我正在使用Excel 2007,MS Visual Basic 6.0。 我需要检查窗口的date格式(例如,是否使用d / m / yyyy或m / d / yyyy),以便使用下面的代码。
Dim lastdateofmonth As Date Dim lastwhichday As String slastdayofmonth = "31" 'if the OS system is using m/d/yyyy then use this lastdateofmonth = (sTxtMMM + "/" + slastdayofmonth + "/" + TxtYYYY) lastwhichday = Weekday(lastdateofmonth) 'if th OS system is using d/m/yyyy then use this lastdateofmonth = (slastdayofmonth+ "/" + sTxtMMM + "/" + TxtYYYY)
任何人都可以帮忙 提前致谢
嗯…我find了一个更好的方法
'========== Check OS Date format======== Dim OSDateFormatType As Integer ' 0 = month-day-year; 1 = day-month-year; 2 = year-month-day If Application.International(xlDateOrder) = 0 Then OSDateFormatType = 0 ElseIf Application.International(xlDateOrder) = 1 Then OSDateFormatType = 1 ElseIf Application.International(xlDateOrder) = 2 Then OSDateFormatType = 2 End If
但是这只适用于excel。
最好的办法:
if Application.International(xlMDY) then ...
真 – 月,日,年假 – 日,月,年
https://msdn.microsoft.com/en-us/library/office/ff840213%28v=office.15%29.aspx