Excel VBA 循環“我中毒了~”

  1. Dim Runtime As Date 
  2.  
  3. Sub RunTimer() 
  4.     Runtime = Now() + TimeValue("00:00:01"
  5.     Application.OnTime Runtime, "my_Procedure" 
  6. End Sub 
  7.  
  8. Sub my_Procedure() 
  9.     Static count As Integer 
  10.     count = count + 1 
  11.     For i = 1 To 10 
  12.         For j = 1 To 20 
  13.             Cells(i + (count - 1) * 10, j) = "我中毒了~~~~" 
  14.             Cells(i + (count - 1) * 10, j).Font.Color = vbRed 
  15.             Cells(i + (count - 1) * 10, j).Font.Size = 10 
  16.         Next 
  17.     Next 
  18.     If count = 10 Then 
  19.         Exit Sub 
  20.     End If 
  21.  
  22.     RunTimer 
  23. End Sub 

就是一個在單元格中的循環,按時間來循環,每過1秒鐘進行一個循環~

爲了不讓其無限循環下去,設置了循環10次即退出~

 

 

吃飯倒計時:

  1. Dim Runtime As Date 
  2.  
  3. Sub RunTimer() 
  4.     Runtime = Now() + TimeValue("00:00:01"
  5.     Application.OnTime Runtime, "my_Procedure" 
  6. End Sub 
  7.  
  8. Sub my_Procedure() 
  9.     Cells(1, 2) = Format(Now(), "h:mm:ss"
  10.     Cells(2, 2) = "18:00:00" 
  11.     Cells(3, 2) = Format(Cells(2, 2) - Cells(1, 2), "h:mm:ss"
  12.     Cells(4, 2) = Format(TimeValue("18:00:00") - TimeValue(Now()), "h:mm:ss"
  13.     RunTimer 
  14. End Sub 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章