任务计划程序和工作簿打开macros

我有一个代码,根据打开的时间做不同的事情。 我正在使用任务计划程序来打开文件。 代码在第二个elseif运行没有问题之前运行该部分。 但是,当从任务调度程序打开文件时,第二个elseif将不会运行。

 Sub workbook_open() Dim time_now As String time_now = Format(Now, "hh:mm:ss") If time_now > "00:05:00" And time_now < "00:05:30" And ThisWorkbook.MultiUserEditing Then Application.DisplayAlerts = False ThisWorkbook.ExclusiveAccess Application.DisplayAlerts = True Application.Calculation = xlCalculationAutomatic ThisWorkbook.Save Application.Quit ElseIf time_now > "00:05:00" And time_now < "00:05:30" And ThisWorkbook.MultiUserEditing = False Then Application.Quit ElseIf time_now > "00:10:00" And time_now < "00:11:00" Then Application.DisplayAlerts = False Call Sheet2.Update If Not ActiveWorkbook.MultiUserEditing Then ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.FullName, accessmode:=xlShared End If Application.DisplayAlerts = True ThisWorkbook.Save Application.Quit Else End If End Sub 

如果我用F8手动运行代码,没有问题。 另外sheet2.update工作没有问题。

不太清楚为什么有人可以指点。 谢谢!

我相信您的macros信任设置阻止任务调度程序打开该文件时的情况。