如何在00:08:00开始录制数据?

时间:2015-10-22 21:26:12

标签: excel vba

使用了几个宏。然后在“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 when workbook opens
    Application.OnTime Now + TimeValue("00:01:00"), "Calcul" 
End Sub

在模块中:

VB:
Public Heure As Date 
Sub Calcul() 
    Heure = Now + TimeValue("00:01:00") 
    Application.OnTime Heure, "Calcul" 
    Range("B65536").End(xlUp).Offset(1) = [A1] 
End Sub 

将在B列(从B2开始)每分钟复制一次单元格A1。现在我希望这个功能在00:08:00开始,但是无法实现。

1 个答案:

答案 0 :(得分:0)

只要工作簿可以保持打开,就可以使用以下代码:

Private Sub Workbook_Open() 
     'start execution when workbook opens
     Application.OnTime Now + TimeValue("00:01:00"), "Calcul" 
End Sub

可以替换为以下内容:

Private Sub Workbook_Open() 
     'start execution at 8 AM when workbook opens
     If Hour(Now()) < 8 Then
         ' If it is before 8 AM
         Application.OnTime Int(Now()) + TimeSerial(8, 0, 0), "Calcul"
         Else
         ' Otherwise begin 8 AM the next day
         Application.OnTime Int(Now()) + 1 + TimeSerial(8, 0, 0), "Calcul"
     End if      
End Sub