0
我想利用用戶輸入(即,「5」)和使該進入的00:05:00的格式(HH:MM:SS) ,其中輸入的數字是計時器中要使用的分鐘數。然後程序會自動啓動一個具有指定時間的計時器。時間將按原樣顯示在B10中,不需要格式化,但定時器將顯示在單元格「I1」中。VBA取用戶輸入(整數),並將其輸入到計時器Excel 2007中
'FUNCTION FOR FORMATTING THE INPUT
Public Function RetTime(IntTime As Integer) As Date
RetTime = TimeSerial(Int(IntTime/10000), Int((IntTime Mod 10000)/100), (IntTime Mod 100))
End Function
'ACCEPTING THE TIME INTERVAL
Sub TimeInterval()
TimeIntervals = InputBox("How long for the intervals?")
Range("B10").Value = TimeIntervals
Range("A2").Select
'setting that time interval to the " I1 " cell
I1 = RetTime(TimeIntervals)
Range("I1").Value = I1
NumOfInterval
End Sub
'THE COUNTDOWN TIMER:
Sub StartTimer()
Future = Now + TimeSerial(0, 0, 1)
Application.OnTime earliestTime:=Future, procedure:="nextTime", _
schedule:=True
End Sub
'From the formatted input that was placed in "I1", make that into a timer
Sub nextTime()
Sheet1.Range("I1").TimeValue = Sheet1.Range("I1").TimeValue - TimeValue("00:00:01")
StartTimer
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime earliestTime:=Future, _
procedure:="nextTime", schedule:=False
End Sub