- Dim Runtime As Date
- Sub RunTimer()
- Runtime = Now() + TimeValue("00:00:01")
- Application.OnTime Runtime, "my_Procedure"
- End Sub
- Sub my_Procedure()
- Static count As Integer
- count = count + 1
- For i = 1 To 10
- For j = 1 To 20
- Cells(i + (count - 1) * 10, j) = "我中毒了~~~~"
- Cells(i + (count - 1) * 10, j).Font.Color = vbRed
- Cells(i + (count - 1) * 10, j).Font.Size = 10
- Next
- Next
- If count = 10 Then
- Exit Sub
- End If
- RunTimer
- End Sub
就是一個在單元格中的循環,按時間來循環,每過1秒鐘進行一個循環~
爲了不讓其無限循環下去,設置了循環10次即退出~
吃飯倒計時:
- Dim Runtime As Date
- Sub RunTimer()
- Runtime = Now() + TimeValue("00:00:01")
- Application.OnTime Runtime, "my_Procedure"
- End Sub
- Sub my_Procedure()
- Cells(1, 2) = Format(Now(), "h:mm:ss")
- Cells(2, 2) = "18:00:00"
- Cells(3, 2) = Format(Cells(2, 2) - Cells(1, 2), "h:mm:ss")
- Cells(4, 2) = Format(TimeValue("18:00:00") - TimeValue(Now()), "h:mm:ss")
- RunTimer
- End Sub