2014-03-30 46 views
2

我使用的是excel 2007,ms visual basic 6.0。 我需要检查窗口os日期格式(例如,是否使用d/m/yyyy或m/d/yyyy),以便使用以下代码。如何使用excel vba检查OS系统日期格式

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) 

任何人都可以提供帮助吗?在此先感谢

+1

检查**日(CDATE(“1/2/14“))**如果它的a ** 1 **那么你有d/m/yyy。如果它的** 2 **你有m/d/yyy –

回答

2

嗯...我发现了一个更好的办法

'========== 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工作。

+2

一个简单的'OSDateFormatType = Application.International(xlDateOrder)'也可以:)顺便说一下'但这只适用于excel.'?你只想在Excel中做到这一点? –