开发者

Determine if today is Monday

开发者 https://www.devze.com 2022-12-31 22:21 出处:网络
开发者_C百科How would I code an IF statement if I was trying to say IF the date today is equal to Monday THEN
开发者_C百科

How would I code an IF statement if I was trying to say

IF the date today is equal to Monday THEN

    Have Outlook prepare 3 emails

ELSE 

    Have Outlook prepare 2 emails

END IF

I just need the "IF the date today is equal to Monday."


If Weekday(Now()) = vbMonday Then
    MsgBox "Monday"
End If


Rather than using an IF statement, I would use a SELECT CASE statement instead:

Select Case Weekday(Now())    
    Case vbMonday    
      'Create 3 emails

    Case vbTuesday    
      'Create 2 emails

    Case Else       
      'Do something else

End Select


VBA offers you a variety of date functions. You would need the Date function to get the actual date, and the Weekday function to get the weekday from a given date.

You condition would have to look like

If Weekday(Date) = vbMonday then
    ' create email
Else
End If


You can:

if (Weekday(Date, vbSunday) = vbMonday) then
   ...
else
   ...
end if
0

精彩评论

暂无评论...
验证码 换一张
取 消