2014-03-30 148 views
0

我得到了一个类似于excel的qn文章,并得到了答案,但它无法在ms单词上工作。如何使用word vba检查操作系统系统日期

我想检查的OS日期格式(无论是它在“日/月/年”或“毫米/日/年”)

我用在Excel VBA中下面的脚本,但它不”没有工作的话,任何人都可以帮忙?

'========== 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 
+0

你互动,通过文字VBA Excel或您需要使用此信息只在字? –

+0

我想知道为什么你需要这个。你[已经解决了上半年的问题](http://blogs.msdn.com/b/oldnewthing/archive/2006/03/23/558887.aspx),不是吗? – GSerg

回答

0

你可能使用UDF(用户定义函数),它可以如下:

Function OSDateFormatType() 
    Dim tmpDate As String 
    tmpDate = CStr(Replace(Replace(DateSerial(2020, 12, 31), "/", ""), "-", "")) 
    If tmpDate = "12312020" Then 
     OSDateFormatType = 0 
    ElseIf tmpDate = "31122020" Then 
     OSDateFormatType = 1 
    ElseIf tmpDate = "202" Then 
     OSDateFormatType = 2 
    Else 
     OSDateFormatType = "check" 
    End If 

End Function