2015-04-17 83 views
0

我正在使用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

使用'選項Explicit'在頂部您模塊能夠在未來迅速消除這些錯誤。 –

回答

1

Today是一個工作表函數,而不是一個VBA函數 - 你要Date

dateToday = Date 

,那麼你其實想測試對Day(dateToday)不僅僅是dateToday

+0

謝謝你的出色工作! – StackUser2014

+0

不客氣。我建議你開始使用'Option Explicit' - 這會提醒你這個問題。 :) – Rory