excel - vba:日期函数返回 "00:00:00"

标签 excel vba

如果传递的值“DateValue”为空,我的下面的代码将返回“00:00:00”

vba:

Public Function forDate(ByVal DateValue As String) As Date
Dim DoDate As Date
If Not IsNull(DateValue) And DateValue <> "" Then
DoDate = CDate(FormatDateTime(DateValue, 1, 10))
forDate = DoDate
End If
End Function

当“DateValue”为空时如何处理??? 请提出答案。

最佳答案

如果您使用 vbNull 而不是 Null,则将 Date 设置为 null 是有效的(即运行时不会出错)。尽管它会返回 #12/31/1899# 而不是 null 本身。您可以稍后根据该已知空值检查日期变量是否为伪空值。

或者您可以将其设置为最小日期DateSerial(100, 1, 1),它将返回#1/1/100#

关于excel - vba:日期函数返回 "00:00:00",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15111218/

相关文章:

excel - 如何获取列中最长字符串的长度(Excel)?

java - 如何使用 Java 8 访问 Excel 作为数据库

excel - 第二次运行 VBA 代码时为 "Run-time error 462 : The remote server machine does not exist or is unavailable"

excel - .复制不随机执行

excel - 引用 If 语句的 'onclick' 事件 - IE 自动化

vba - Excel VBA 如果 cell.Value =... 那么

java - 通过从模板编程创建 Excel 报告

java - Apache POI - 读取由 TEXT() 公式格式化的单元格

excel - 复制和粘贴的宏扩展不起作用

excel - excel中的圆函数。如何四舍五入到特定数字?