返回列表 上一主題 發帖

ontime schedule:=false 有問題

ontime schedule:=false 有問題

執行 timestop 沒有問題,但放在 Worksheet_Calculate()
時間到執行為何錯在
Application.OnTime EarliestTime:=tbme, _
        Procedure:="showtime", Schedule:=False




Public abf As Date
Public tbme As Date
Sub showtime()
abf = TimeValue("00:00:01")
tbme = Time + abf
    Application.OnTime tbme, "showtime"
Sheets("Sheet3").Range("t1").Value = Hour(Now) & ":" & Minute(Now) & ":" & Second(Now)
End Sub


Sub timestop()
Application.OnTime EarliestTime:=tbme, _
        Procedure:="showtime", Schedule:=False
   End Sub



Private Sub Worksheet_Calculate()
If Format(Now, "hh:mm:ss") = "13:30:34" Then
timestop
End If
end sub

看起來好像是tbme沒資料
因為沒執行到Sub showtime()這一段程式
  1. Public abf As Date
  2. Public tbme As Date
  3. Sub showtime()
  4. abf = TimeValue("00:00:01")
  5. tbme = Time + abf
  6.     Application.OnTime tbme, "showtime"
  7. Sheets("Sheet3").Range("t1").Value = Hour(Now) & ":" & Minute(Now) & ":" & Second(Now)
  8. End Sub


  9. Sub timestop()
  10. Application.OnTime EarliestTime:=tbme, _
  11.         Procedure:="showtime", Schedule:=False
  12.    End Sub



  13. Private Sub Worksheet_Calculate()
  14. If Format(Now, "hh:mm:ss") = "13:30:34" Then
  15. showtime
  16. timestop
  17. End If
  18. End Sub
複製代碼
增加showtime在第三段的程式
就可以順利執行了
動念成因積因成果 by huijuang

TOP

看起來好像是tbme沒資料
增加showtime在第三段的程式
就可以順利執行了
huijuang 發表於 2014-3-14 13:48

showtime 已經手動執行...........這樣會重覆執行???變成跑兩個程序

TOP

回復 3# t8899

showtima手動執行應該不會把tbme資料帶出來
建議你用逐行執行
然後把區域變數視窗打開
應該可以看看tbme是否有資料帶出來
動念成因積因成果 by huijuang

TOP

回復  t8899

showtima手動執行應該不會把tbme資料帶出來
建議你用逐行執行
然後把區域變數視窗打開
...
huijuang 發表於 2014-3-17 08:05


區域變數視窗如何打開 ???

TOP

回復 5# t8899

區域變數視窗如下:
在debug時滿好用的
    v.gif
動念成因積因成果 by huijuang

TOP

        靜思自在 : 人生最大的成就是從失敗中站起來。
返回列表 上一主題