|
刚想起来,代码中没有对数值的大小做判断,失误。- Dim dTime As Double
- Dim lRow As Long
- Dim strInput$
- Sub StartMoveDown()
- Dim strPrompt As String
- On Error Resume Next
- If dTime Then Call StopMoveDown
- strPrompt = "输入延迟的秒数" & vbNewLine
- strPrompt = strPrompt & "[两位数字表示:例如1秒,输入01" & vbNewLine
- strPrompt = strPrompt & "数值范围在01-59之间"
- strInput = InputBox(strPrompt, Default:="05")
-
- If Len(strInput) <> 2 Or (Not VBA.IsNumeric(strInput)) Then
- MsgBox "录入的非数值或非两位数字"
- Exit Sub
- End If
-
- If strInput < 1 Or strInput > 59 Then
- MsgBox "输入的数值不在01-59区间内"
- Exit Sub
- End If
- lRow = 0
- Call selectCell
- End Sub
- Sub StopMoveDown()
- On Error Resume Next
- Application.OnTime dTime, "selectcell", , False
- End Sub
- Sub selectCell()
- If lRow = Rows.Count Then lRow = 0
- Cells(lRow + 1, 1).Activate
- dTime = Now + TimeValue("00:00:" & strInput)
- Application.OnTime dTime, "selectcell"
- lRow = lRow + 1
- End Sub
复制代码 |
|