在00:08:15而不是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"