如何使用excel vba检查操作系统系统日期格式

Leo*_*eon 5 excel vba

我使用的是Excel 2007,MS Visual Basic 6.0。我需要检查窗口操作系统日期格式(例如,是否使用 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)
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮忙吗?提前致谢

Leo*_*eon 6

嗯...我找到了更好的方法

'========== 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
Run Code Online (Sandbox Code Playgroud)

但这只适用于excel。

  • 一个简单的“OSDateFormatType = Application.International(xlDateOrder)”也可以:)顺便说一句,“但这仅适用于 Excel”是什么意思?您只想在 Excel 中执行此操作,对吗? (2认同)