如何仅在工作日 运行 一个 Workbook_Open 代码? (M-F)
How do I Run a Workbook_Open code only during the weekdays? (M-F)
我有一系列 Application.OnTime 代码,需要在一周中的特定日子 (M-F) 运行。 Saturday/Sunday 上 运行 不需要这些代码。我如何只输入 运行 M-F? Application.OnKey 代码需要每天 运行。
谢谢
'Set keyboard shortcuts
Application.OnKey "^+{UP}", "Sheet4.SpinButton1_SpinDown"
Application.OnKey "^+{DOWN}", "Sheet4.SpinButton1_SpinUp"
If Weekday(Now()) > 2 And Weekday(Now()) < 7 Then Call Workbook_Open
Application.OnTime TimeValue("17:15:00"), "Saveit"
Application.OnTime TimeValue("17:17:00"), "MASTER"
Application.OnTime TimeValue("17:33:00"), "MASTER"
Application.OnTime TimeValue("17:59:00"), "MASTER"
Application.OnTime TimeValue("18:21:00"), "MASTER"
Application.OnTime TimeValue("18:45:00"), "MASTER"
Application.OnTime TimeValue("19:03:00"), "MASTER"
Application.OnTime TimeValue("19:23:00"), "MASTER"
Application.OnTime TimeValue("19:41:00"), "MASTER"
End Sub```
如果你的代码在没有 IF
的情况下工作正常,那么我在评论中建议的应该工作。
你是这样修改你的代码来回应我的评论的吗?
我用了 Date
而不是 Now
但它们应该给出相同的结果。 VBA
中不需要 Now
之后的 ()
我也使用了 >=2
,因为你指出 M-F,即:你想 include Monday
...
'Set keyboard shortcuts
Application.OnKey "^+{UP}", "Sheet4.SpinButton1_SpinDown"
Application.OnKey "^+{DOWN}", "Sheet4.SpinButton1_SpinUp"
If Weekday(Date) >= 2 And Weekday(Date) < 7 Then
Application.OnTime TimeValue("17:15:00"), "Saveit"
Application.OnTime TimeValue("17:17:00"), "MASTER"
Application.OnTime TimeValue("17:33:00"), "MASTER"
Application.OnTime TimeValue("17:59:00"), "MASTER"
Application.OnTime TimeValue("18:21:00"), "MASTER"
Application.OnTime TimeValue("18:45:00"), "MASTER"
Application.OnTime TimeValue("19:03:00"), "MASTER"
Application.OnTime TimeValue("19:23:00"), "MASTER"
Application.OnTime TimeValue("19:41:00"), "MASTER"
End If
End Sub
我有一系列 Application.OnTime 代码,需要在一周中的特定日子 (M-F) 运行。 Saturday/Sunday 上 运行 不需要这些代码。我如何只输入 运行 M-F? Application.OnKey 代码需要每天 运行。 谢谢
'Set keyboard shortcuts
Application.OnKey "^+{UP}", "Sheet4.SpinButton1_SpinDown"
Application.OnKey "^+{DOWN}", "Sheet4.SpinButton1_SpinUp"
If Weekday(Now()) > 2 And Weekday(Now()) < 7 Then Call Workbook_Open
Application.OnTime TimeValue("17:15:00"), "Saveit"
Application.OnTime TimeValue("17:17:00"), "MASTER"
Application.OnTime TimeValue("17:33:00"), "MASTER"
Application.OnTime TimeValue("17:59:00"), "MASTER"
Application.OnTime TimeValue("18:21:00"), "MASTER"
Application.OnTime TimeValue("18:45:00"), "MASTER"
Application.OnTime TimeValue("19:03:00"), "MASTER"
Application.OnTime TimeValue("19:23:00"), "MASTER"
Application.OnTime TimeValue("19:41:00"), "MASTER"
End Sub```
如果你的代码在没有 IF
的情况下工作正常,那么我在评论中建议的应该工作。
你是这样修改你的代码来回应我的评论的吗?
我用了 Date
而不是 Now
但它们应该给出相同的结果。 VBA
Now
之后的 ()
我也使用了 >=2
,因为你指出 M-F,即:你想 include Monday
...
'Set keyboard shortcuts
Application.OnKey "^+{UP}", "Sheet4.SpinButton1_SpinDown"
Application.OnKey "^+{DOWN}", "Sheet4.SpinButton1_SpinUp"
If Weekday(Date) >= 2 And Weekday(Date) < 7 Then
Application.OnTime TimeValue("17:15:00"), "Saveit"
Application.OnTime TimeValue("17:17:00"), "MASTER"
Application.OnTime TimeValue("17:33:00"), "MASTER"
Application.OnTime TimeValue("17:59:00"), "MASTER"
Application.OnTime TimeValue("18:21:00"), "MASTER"
Application.OnTime TimeValue("18:45:00"), "MASTER"
Application.OnTime TimeValue("19:03:00"), "MASTER"
Application.OnTime TimeValue("19:23:00"), "MASTER"
Application.OnTime TimeValue("19:41:00"), "MASTER"
End If
End Sub