我有一个类似的关于excel的qn帖子并且得到了答案,但是它无法用于ms字。
我想检查操作系统日期格式(是否在" dd / mm / yyyy"或" mm / dd / yyyy")
我在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 :(得分: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 = "20201231" Then
OSDateFormatType = 2
Else
OSDateFormatType = "check"
End If
End Function