我想接受用户输入(即“5”)并将其格式化为00:05:00(hh:mm:ss),其中输入的数字是计时器中使用的分钟数。然后程序将自动启动一个具有指定时间的计时器。时间将按原样显示在B10中,不需要格式化,但计时器将显示在单元格“I1”中。
'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
答案 0 :(得分:0)
如果他们遵循输入框中的格式,您可以使用此代码。 在此示例中,00:05:00的用户输入将导致变量timer = 5
Sub ashTime()
Dim timer As String
timer = minute(InputBox("Enter minutes as HH:MM:SS"))
MsgBox timer
End Sub