vba 确定今天是否是星期一
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2913717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Determine if today is Monday
提问by Edmond
How would I code an IF statement if I was trying to say
如果我想说,我将如何编写 IF 语句
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."
我只需要“如果今天的日期等于星期一”。
回答by dendarii
If Weekday(Now()) = vbMonday Then
MsgBox "Monday"
End If
回答by Neil Knight
Rather than using an IF statement, I would use a SELECT CASE statement instead:
我不使用 IF 语句,而是使用 SELECT CASE 语句:
Select Case Weekday(Now())
Case vbMonday
'Create 3 emails
Case vbTuesday
'Create 2 emails
Case Else
'Do something else
End Select
回答by Dirk Vollmar
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.
VBA 为您提供了多种日期函数。您需要Date
获取实际日期的Weekday
函数,以及获取给定日期的工作日的函数。
You condition would have to look like
你的条件必须看起来像
If Weekday(Date) = vbMonday then
' create email
Else
End If
回答by Alex K.
You can:
你可以:
if (Weekday(Date, vbSunday) = vbMonday) then
...
else
...
end if