在 00:08:15 而不是 00:08:00 开始执行代码

Start code execution at 00:08:15 instead of 00:08:00

在"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 开始。我该怎么办?

以下代码行控制您的 "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"