在弹出输入框中将短日期转换为长日期

时间:2013-04-27 18:31:01

标签: excel date excel-vba vba

我有一个弹出框的代码,要求提供日期Ex:2013年4月5日,如何自动将其转换为长日期格式?

我试过

strUserResponse = FormatDateTime(Date, vbLongDate)

但它只是给了我今天的日期

由于

Public Function AskForDeadline() As String
Dim strUserResponse As String

strUserResponse = InputBox("Enter attribute_5: Survey Deadline - In Short Date Format Ex: 4/9/2012 Will convert to LOND date AUTOMATICALLY")
strUserResponse = FormatDateTime(Date, vbLongDate)
ActiveSheet.Cells(2, 9).Value = strUserResponse 'the 2, 9 is the cell reference for I2 - row 2, column 9.


End Function

1 个答案:

答案 0 :(得分:2)

正如我在上一篇文章中提到的,Inputbox不是获取约会的最佳方式,但如果您仍想继续这样做,那么请更改

strUserResponse = FormatDateTime(Date, vbLongDate)

strUserResponse = FormatDateTime(strUserResponse, vbLongDate)

您正在获取当前日期,因为您要在该代码行中转换Date,这将为您提供今天的日期。

相关问题