应用于 TextBox 值的 DateAdd 函数在 VBA 中显示 1900 年以来的日期
我有代码可以将用户输入与文本框中必须包含的日期进行比较。
Dim tddate As Date
Dim expdate As String
Dim inputdate As String
tddate = Worksheets("Sheet3").Range("pdate").Value
inputdate = TextBox1.Value
expdate = Format(DateAdd("m", 18, tddate), "dd/mm/yyyy")
If inputdate = expdate Then
Range("A1").Value = TextBox1.Value
Else
MsgBox "Input the correct date"
Cancel = True
End If
直到昨天它才起作用。
今天,如果我 Debug.Print
expdate
变量,它会显示 30/06/1901。
如果我Debug.Print Now
它会显示正确的日期。
我使用的是 Excel 2019。
我在另一台笔记本电脑上使用 Excel 2016 尝试了该工作簿,它显示了相同的内容。
I have code to compare user input with the date that must be in a textbox.
Dim tddate As Date
Dim expdate As String
Dim inputdate As String
tddate = Worksheets("Sheet3").Range("pdate").Value
inputdate = TextBox1.Value
expdate = Format(DateAdd("m", 18, tddate), "dd/mm/yyyy")
If inputdate = expdate Then
Range("A1").Value = TextBox1.Value
Else
MsgBox "Input the correct date"
Cancel = True
End If
Until yesterday it worked.
Today if I Debug.Print
the expdate
variable it shows 30/06/1901.
If I Debug.Print Now
it shows the correct date.
I am using Excel 2019.
I tried the workbook on a different laptop with Excel 2016 and it shows the same thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用真实的日期值,而不是文本:
Try working with true date values, not text: