检查 vba excel 2010 64 位中的特定日期格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9540005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 15:26:09  来源:igfitidea点击:

Check for specific date format in vba excel 2010 64-bit

exceldatetimeexcel-vbavba

提问by Somebody

I'm doing some validations to a cell where the user inputs a date value. The correct format I'm expecting is "m/d/yyyy", so I need a way to check that the user enter the date in that format.

我正在对用户输入日期值的单元格进行一些验证。我期望的正确格式是“m/d/yyyy”,所以我需要一种方法来检查用户是否以该格式输入日期。

How can I achieve that?

我怎样才能做到这一点?

here are some of the validations I've made:

以下是我所做的一些验证:

Dim StartDate As String
 Dim EndDate As String
 With Sheet1
    StartDate = WorksheetFunction.Trim(.Range("F2").Value)
    EndDate = WorksheetFunction.Trim(.Range("F3").Value)
 End With

 'Dates validations

 If StartDate = "" Or EndDate = "" Then
    MsgBox ("Dates can't be empty")
    Exit Sub
 End If

 If Not IsDate(StartDate) Or Not IsDate(EndDate) Then
    MsgBox ("Please check dates format")
    Exit Sub
 End If

 If CDate(StartDate) > CDate(EndDate) Then
    MsgBox ("Start Date can't be greater than End Date")
    Exit Sub
 End If

采纳答案by Somebody

Siddharth Rout's solution:

Siddharth Rout 的解决方案:

Hope this helps? support.microsoft.com/kb/211485.

希望这可以帮助?support.microsoft.com/kb/211485