在" ThisWorkbook"中,粘贴:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Stop execution when workbook closes
On Error Resume Next
Application.OnTime Heure, "Calcul", , False
End Sub
Private Sub Workbook_Open()
'start execution at 8 AM when workbook opens
If Hour(Now()) < 8 & Minute(Now()) < 5 Then
' If it is before 8 AM
Application.OnTime Int(Now()) + TimeSerial(8, 5, 0), "Calcul"
Else
' Otherwise begin 8 AM the next day
Application.OnTime Int(Now()) + 1 + TimeSerial(8, 5, 0), "Calcul"
End If
End Sub
在模块中,粘贴:
Public Heure As Date
Sub Calcul()
Heure = Now + TimeValue("00:15:00")
Application.OnTime Heure, "Calcul"
With [B65536].End(xlUp)(2)
.Item(1, 1) = [A1]
.Item(1, 3) = [C1]
End With
End Sub
我希望此代码从00:08:15而不是00:08:00开始。我该怎么办?
答案 0 :(得分:1)
当“Calcul”函数启动时,以下代码行控制:
Application.OnTime Int(Now()) + TimeSerial(8, 5, 0), "Calcul"
...
Application.OnTime Int(Now()) + 1 + TimeSerial(8, 5, 0), "Calcul"
目前在08:05:00(不是00:08:00!)运行您的代码。要让它们在08:15:00运行,请将它们更改为:
Application.OnTime Int(Now()) + TimeSerial(8, 15, 0), "Calcul"
...
Application.OnTime Int(Now()) + 1 + TimeSerial(8, 15, 0), "Calcul"