[算表] Do While LOOP & Application.OnTime

作者: ckingsu (ckingsu)   2025-01-23 13:16:50
軟體: excel
版本: 2021
Sub atime123()
Range("Aa21") = 0
time0 = Time()
time1 = Time()
Do While Range("Aa21") <> Range("Ab21")
time1 = Time() + TimeSerial(0, 0, 1)
Range("Aa21") = DateDiff("s", time0, time1)
DoEvents
Loop
End Sub
雖有 DoEvents 再執行Application.OnTime程序 還是沒辦法正確執行 ??
作者: newacc (XD)   2025-01-23 17:26:00
你認為怎樣是正確執行?OnTime寫在哪裡?https://i.imgur.com/O7kMNmq.mp4https://i.imgur.com/5HkP3EL.png
作者: ckingsu (ckingsu)   2025-01-23 20:39:00
Range("Aa21") = DateDiff("s", time0, time1)改用debug.pring, 或用變數取代application.ontime 就能正確執行不知為何會如此?我需要儲存格動態秒數,不知怎麼改?在不影響其他程序的情況下
作者: newacc (XD)   2025-01-24 02:56:00
我提供的螢幕錄影就是你說的儲存格動態秒數吧?是由你文章裡的程式碼改的,沒辦法執行的話,需要更詳細的程式碼才有辦法判斷了你的OnTime是寫在哪裡?呼叫什麼?
作者: ckingsu (ckingsu)   2025-01-24 05:48:00
my = #12:00:10 AM#The_Time = Now + myApplication.OnTime The_Time, "timestock"Range("J16").Value = Format(The_Time, "hh:mm:ss")10秒執行一次timestocktimestock->寫一些DDE的資料到儲存格(程式碼不短就不引出on time 在第二個10秒就不動了 ?改 A=DateDiff("s", time0, time1)就會動了我剛又隨便寫一個簡單的on time 測試也是不行sub acde123()[a1] = [a1] + 1sw = #12:00:02 AM#aaa = Now + swApplication.OnTime aaa, "acde123"end sub

Links booklink

Contact Us: admin [ a t ] ucptt.com