如果声明当前日期

时间:2015-04-17 09:29:13

标签: excel vba excel-vba

我正在使用ElseIf语句和系统日期来创建输出。

到目前为止,这是我的代码:

Dim dateToday As Date
Dim fifth As Integer
Dim fifthteenth As Integer
Dim twentyEighth As Integer
Dim thirtieth As Integer

dateToday = Today
fifth = 5
fifthteenth = 17 'this is changed to todays date for testing otherwise its 15
twentyEighth = 28
thirtieth = 30

If fifth = dateToday Then
    MsgBox ("Today is the fifth")
ElseIf fifthteenth = dateToday Then
    MsgBox ("Today is the fifthteenth")
ElseIf twentyEighth = dateToday Then
    MsgBox ("Today is the 28th")
ElseIf thirtieth = dateToday Then
    MsgBox ("Today is the 30th")
Else
    MsgBox ("You do not need to do anything yet")
End If

直接到最后并生成最后一个消息框。

1 个答案:

答案 0 :(得分:1)

Today是工作表函数,而不是VBA函数 - 您想要Date

dateToday = Date

然后您实际上想要针对Day(dateToday)而不仅仅是dateToday

进行测试